diff --git a/README.md b/README.md index fbe2221..a0fc6da 100755 --- a/README.md +++ b/README.md @@ -58,12 +58,12 @@ Gemini > Markdown > HTML, which means that the last of these formats you will us ## Metadata persistence -IDs are attributed to titles according to their content, therefore modifying a title breaks links to page sections. +HTML IDs are attributed to headings according to their content, therefore modifying a title breaks links to page sections. ### For atom feeds -* Make sure modification timestamps of source files are preserved. For example, `cp --preserve=timestamps` must be used instead of just `cp` when backing up or migrating. -* Renaming/moving a page creates a new page and delete the older. +* Except when a page name start with a date formated as `YYYY-MM-DD-`, the `updated` element of each Atom entry is determined by the modification timestamp of the source file. If using `cp` to backup or transfer files, its `--preserve=timestamps` option should be added. +* Renaming/moving a page creates a new page and deletes the older. ## Dependencies diff --git a/mkht.php b/mkht.php index 7c98624..2b6f61c 100755 --- a/mkht.php +++ b/mkht.php @@ -126,6 +126,11 @@ foreach ($pages as $node) { $path_parts_src = pathinfo($src); $path_parts_target = pathinfo($target); + $last_update = match (preg_match("/^(?[0-9]{4})-(?[0-9]{2})-(?[0-9]{2})-/D", $path_parts_src['basename'], $date)) { + 1 => (new DateTime())->setDate($date['year'], $date['month'], $date['day'])->format('U'), + 0 => (new SplFileInfo(str_replace(SITE . 'cache/', SITE, $src)))->getMTime(), + }; + $base_filepath_src = $path_parts_src['dirname'] . '/' . $path_parts_src['filename']; $base_filepath_target = $path_parts_target['dirname'] . '/' . $path_parts_target['filename']; @@ -136,7 +141,7 @@ foreach ($pages as $node) { $title = $matches['title'] ?? NULL; if (!file_exists($base_filepath_target . '.html') OR (filemtime($src) > filemtime($base_filepath_target . '.html')) OR $opt['force']) { - echo 'Compiling ' . $src . ' ' . date("Y-m-d H:i:s", $node_info->getMTime()) . LF; + echo 'Compiling ' . $src . ' ' . date("Y-m-d H:i:s", $last_update) . LF; // Execute PHP code ob_start(); @@ -295,7 +300,7 @@ foreach ($pages as $node) { <?= $title ?> - getMTime()) ?> + ' . LF; @@ -307,7 +312,6 @@ foreach ($pages as $node) { foreach (explode('/', $relative_addr) as $level => $unused) { $dir = implode('/', array_slice(explode('/', $relative_addr), 0, $level)) . '/'; - $last_update = $node_info->getMTime(); $dirs_entries_per_lang['all'][$dir] = ($dirs_entries_per_lang['all'][$dir] ?? '') . $atom_entry; $dirs_entries_per_lang[$lang][$dir] = ($dirs_entries_per_lang[$lang][$dir] ?? '') . $atom_entry;