fix atom updated element + detect YYYY-MM-DD-*

This commit is contained in:
Miraty 2024-06-27 17:59:09 +02:00
parent a6bf0c3581
commit c40470d3de
2 changed files with 10 additions and 6 deletions

View file

@ -58,12 +58,12 @@ Gemini > Markdown > HTML, which means that the last of these formats you will us
## Metadata persistence ## 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 ### 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. * 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 delete the older. * Renaming/moving a page creates a new page and deletes the older.
## Dependencies ## Dependencies

View file

@ -126,6 +126,11 @@ foreach ($pages as $node) {
$path_parts_src = pathinfo($src); $path_parts_src = pathinfo($src);
$path_parts_target = pathinfo($target); $path_parts_target = pathinfo($target);
$last_update = match (preg_match("/^(?<year>[0-9]{4})-(?<month>[0-9]{2})-(?<day>[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_src = $path_parts_src['dirname'] . '/' . $path_parts_src['filename'];
$base_filepath_target = $path_parts_target['dirname'] . '/' . $path_parts_target['filename']; $base_filepath_target = $path_parts_target['dirname'] . '/' . $path_parts_target['filename'];
@ -136,7 +141,7 @@ foreach ($pages as $node) {
$title = $matches['title'] ?? NULL; $title = $matches['title'] ?? NULL;
if (!file_exists($base_filepath_target . '.html') OR (filemtime($src) > filemtime($base_filepath_target . '.html')) OR $opt['force']) { 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 // Execute PHP code
ob_start(); ob_start();
@ -295,7 +300,7 @@ foreach ($pages as $node) {
<entry> <entry>
<title><?= $title ?></title> <title><?= $title ?></title>
<id><?= $public_id ?></id> <id><?= $public_id ?></id>
<updated><?= date('c', $node_info->getMTime()) ?></updated> <updated><?= date('c', $last_update) ?></updated>
<?php <?php
foreach ($config['base-url'] as $base_url) foreach ($config['base-url'] as $base_url)
echo ' <link rel="alternate" type="text/html" href="' . $base_url . $relative_addr . '"></link>' . LF; echo ' <link rel="alternate" type="text/html" href="' . $base_url . $relative_addr . '"></link>' . LF;
@ -307,7 +312,6 @@ foreach ($pages as $node) {
foreach (explode('/', $relative_addr) as $level => $unused) { foreach (explode('/', $relative_addr) as $level => $unused) {
$dir = implode('/', array_slice(explode('/', $relative_addr), 0, $level)) . '/'; $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['all'][$dir] = ($dirs_entries_per_lang['all'][$dir] ?? '') . $atom_entry;
$dirs_entries_per_lang[$lang][$dir] = ($dirs_entries_per_lang[$lang][$dir] ?? '') . $atom_entry; $dirs_entries_per_lang[$lang][$dir] = ($dirs_entries_per_lang[$lang][$dir] ?? '') . $atom_entry;