このファイルはテンプレートです。
Last active
February 8, 2021 10:53
-
-
Save ndxbn/cf9e6f8797c59d1cfa31526480da57e8 to your computer and use it in GitHub Desktop.
毎週火曜日に記事投稿をしたい
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$baseDir = dirname(__DIR__); | |
$postsDir = realpath($baseDir."/_posts"); | |
$posts = scandir($postsDir, SCANDIR_SORT_DESCENDING ); | |
$lastPostDateString = substr($posts[1], 0, 10); | |
/** posts の中で一番新しいの日付のやつ */ | |
$lastPost = new DateTimeImmutable($lastPostDateString); | |
/** 直近の火曜日 */ | |
$today = new DateTimeImmutable(); | |
$fileNameSuffix = "-0.md"; // "-0" は記事タイトルで、 Jekill の post の制限的なやつ。".md" は拡張子 | |
foreach (new DatePeriod($lastPost, new DateInterval("P1W"), $today) as $postDate) { | |
$postDateString = $postDate->format("Y-m-d") . $fileNameSuffix; | |
$newFilePath = $postsDir."/".$postDateString; | |
if (file_exists($newFilePath)) { | |
continue; | |
} | |
// var_dump([$postDateString, $newFilePath]); | |
file_put_contents($newFilePath, file_get_contents("./template.md")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment