From a2b600a3a41cb3fd21bfcf25b22d5bac685e3fba Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Thu, 24 Jul 2008 18:18:33 -0600 Subject: [PATCH] Add support for backdating creation times using Signed-off-by: Edward Z. Yang --- XHTMLCompiler/DOMFilter/Metadata.php | 20 ++++++++++++++++++-- XHTMLCompiler/Page.php | 14 ++++++++++++++ smoketests/DOMFilter/News/2008/0101-backdated.xhtml | 19 +++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 smoketests/DOMFilter/News/2008/0101-backdated.xhtml diff --git a/XHTMLCompiler/DOMFilter/Metadata.php b/XHTMLCompiler/DOMFilter/Metadata.php index 2a45bde..d97d8e1 100644 --- a/XHTMLCompiler/DOMFilter/Metadata.php +++ b/XHTMLCompiler/DOMFilter/Metadata.php @@ -13,11 +13,27 @@ class XHTMLCompiler_DOMFilter_Metadata extends XHTMLCompiler_DOMFilter { $head = $dom->getElementsByTagName('head')->item(0); $date = $page->getCreatedTime(); + // check if the meta element already exists + $meta = $dom->createElement('meta'); + $append = true; + foreach ($head->getElementsByTagName('meta') as $node) { + if ($node->getAttribute('name') == 'Date') { + // it exists: use this date as the "real" date. + $meta = $node; + if ($t = $meta->getAttribute('content')) { + // this code is slightly redundant since getCreatedTime() + // will have already accounted for this. Still, can't hurt. + $date = new DateTime($t); + } + $append = false; + break; + } + } + // only write if we have a valid date if ($date) { - $meta = $dom->createElement('meta'); $meta->setAttribute('name', 'Date'); $meta->setAttribute('content', $date->format('c')); - $head->appendChild($meta); + if ($append) $head->appendChild($meta); } } diff --git a/XHTMLCompiler/Page.php b/XHTMLCompiler/Page.php index 8c7c7cf..81dea1f 100644 --- a/XHTMLCompiler/Page.php +++ b/XHTMLCompiler/Page.php @@ -284,6 +284,20 @@ class XHTMLCompiler_Page * Retrieves the DateTime this page was created, according to Git's logs. */ public function getCreatedTime() { + // As a backwards-compatibility measure, we allow the first meta tag + // with the specific signature: + // source->get(); + if (($p = strpos($source, 'getRepo(); // This is extremely memory inefficient, but I can't figure out // how to get Git to limit the commits (-n) without undoing diff --git a/smoketests/DOMFilter/News/2008/0101-backdated.xhtml b/smoketests/DOMFilter/News/2008/0101-backdated.xhtml new file mode 100644 index 0000000..d95d506 --- /dev/null +++ b/smoketests/DOMFilter/News/2008/0101-backdated.xhtml @@ -0,0 +1,19 @@ + + + + + Backdated - My Blog + + + + +

Backdated

+
+

+ This is a backdated entry. +

+
+ + \ No newline at end of file -- 2.11.4.GIT