aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sisudoc/outputs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sisudoc/outputs')
-rw-r--r--src/sisudoc/outputs/io_out/epub3.d73
-rw-r--r--src/sisudoc/outputs/io_out/odt.d15
2 files changed, 16 insertions, 72 deletions
diff --git a/src/sisudoc/outputs/io_out/epub3.d b/src/sisudoc/outputs/io_out/epub3.d
index 7ffe978..211176e 100644
--- a/src/sisudoc/outputs/io_out/epub3.d
+++ b/src/sisudoc/outputs/io_out/epub3.d
@@ -250,74 +250,11 @@ template outputEPub3() {
auto _ns = sha1UUID("sisudoc.org", dnsNamespace);
return sha1UUID(_doc_uid, _ns).toString;
}
- /+ ↓ the last modified time, as EPUB3 requires it: exactly one dcterms:modified
- on the package, in UTC to the second, CCYY-MM-DDThh:mm:ssZ
- .
- Taken from the document rather than from the clock, so that an epub is
- a function of its source and not of the moment it was built. Read in
- order: SOURCE_DATE_EPOCH where the environment sets it, which is the
- reproducible-builds convention and lets a packager pin every artefact
- of one run; then the document's own date.modified; then
- date.published. The clock is the last resort, for a document that says
- nothing about when it is from.
- .
- Before this, two runs over unchanged markup produced different epub
- bytes, so no comparison of epub output could tell a real change from
- the seconds between two builds.
- .
- A document date is loose markup: "1991", "2006-03" and "2021-12-00"
- all occur in the sample set, and a month or day of 00 is not a date.
- A missing or zero part becomes 01, and a day out of range for its
- month falls back to the first, so what is written is always a valid
- timestamp.
+ /+ ↓ the last modified time EPUB3 requires, exactly one dcterms:modified on
+ the package in UTC to the second, comes from doc_matters.modified_utc.
+ Set in spine rather than here because an odt's office:meta needs the
+ same instant, and a single definition cannot drift apart.
+/
- string _epub_modified_utc(M)(M _meta) {
- import std.datetime : Clock, UTC, SysTime, Date, unixTimeToStdTime;
- import std.process : environment;
- import std.regex : ctRegex, matchFirst;
- string _stamp(int _y, int _mo, int _d) {
- return format("%04d-%02d-%02dT00:00:00Z", _y, _mo, _d);
- }
- /+ ↓ a build may pin every artefact of the run +/
- string _sde = environment.get("SOURCE_DATE_EPOCH", "");
- if (_sde.length > 0) {
- try {
- auto _t = SysTime(unixTimeToStdTime(_sde.to!long), UTC());
- return format("%04d-%02d-%02dT%02d:%02d:%02dZ",
- _t.year, _t.month.to!int, _t.day, _t.hour, _t.minute, _t.second);
- } catch (Exception) {
- }
- }
- /+ ↓ what the document itself says +/
- static auto _rgx_date
- = ctRegex!(`^\s*(?P<y>\d{4})(?:[-/](?P<m>\d{1,2}))?(?:[-/](?P<d>\d{1,2}))?`);
- foreach (_said; [_meta.date_modified, _meta.date_published]) {
- if (_said.length == 0) {
- continue;
- }
- if (auto _m = _said.matchFirst(_rgx_date)) {
- int _y = _m["y"].to!int;
- int _mo = (_m["m"].length > 0) ? _m["m"].to!int : 1;
- int _d = (_m["d"].length > 0) ? _m["d"].to!int : 1;
- if (_mo < 1 || _mo > 12) {
- _mo = 1;
- }
- if (_d < 1) {
- _d = 1;
- }
- try {
- cast(void) Date(_y, _mo, _d);
- } catch (Exception) {
- _d = 1;
- }
- return _stamp(_y, _mo, _d);
- }
- }
- /+ ↓ the document says nothing: the run's own time, as before +/
- auto _t = Clock.currTime(UTC());
- return format("%04d-%02d-%02dT%02d:%02d:%02dZ",
- _t.year, _t.month.to!int, _t.day, _t.hour, _t.minute, _t.second);
- }
string epub3_mimetypes() {
string o;
o = format(q"┃application/epub+zip┃") ~ "\n";
@@ -373,7 +310,7 @@ template outputEPub3() {
? "" : xhtml_format.special_characters_plain_date(doc.matters.conf_make_meta.meta.date_published),
(doc.matters.conf_make_meta.meta.rights_copyright.empty)
? "" : xhtml_format.special_characters_plain(doc.matters.conf_make_meta.meta.rights_copyright),
- _epub_modified_utc(doc.matters.conf_make_meta.meta),
+ doc.matters.modified_utc,
_epub_a11y_metadata(doc),
(pth_epub3.fn_oebps_css).chompPrefix("OEBPS/"),
);
diff --git a/src/sisudoc/outputs/io_out/odt.d b/src/sisudoc/outputs/io_out/odt.d
index 711be50..40d760d 100644
--- a/src/sisudoc/outputs/io_out/odt.d
+++ b/src/sisudoc/outputs/io_out/odt.d
@@ -959,20 +959,27 @@ template outputODT() {
string meta_xml(M)(
auto ref M doc_matters,
) {
- /+ (meta_xml includes output time-stamp) +/
+ /+ ↓ office:meta carries the document's own date and language, not the run's
+ time-stamp. Both dates were taken from doc_matters.generated_time, which
+ is a human-readable run stamp ("2026-9-17 [38/3] 18:39:35") and not a
+ valid xsd:dateTime, which is what ODF asks for here; so the field was
+ malformed and different on every run. dc:language was a hard-coded
+ "en-US".
+ +/
string _meta_xml = format(q"┃<?xml version="1.0" encoding="UTF-8"?>
<office:document-meta xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xl="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:grddl="http://www.w3.org/2003/g/data-view#" office:version="1.2">
<office:meta>
<meta:generator>%s</meta:generator>
<meta:creation-date>%s</meta:creation-date>
<dc:date>%s</dc:date>
- <dc:language>en-US</dc:language>
+ <dc:language>%s</dc:language>
</office:meta>
</office:document-meta>
┃",
doc_matters.generator_program.name_and_version,
- doc_matters.generated_time,
- doc_matters.generated_time,
+ doc_matters.modified_utc,
+ doc_matters.modified_utc,
+ doc_matters.src.language_tag,
);
return _meta_xml;
}