|
|
@@ -336,6 +336,11 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
}
|
|
|
|
|
|
initialize() {
|
|
|
+ this.options.saveDate = new Date();
|
|
|
+ this.options.saveUrl = this.options.url;
|
|
|
+ if (this.options.enableMaff) {
|
|
|
+ this.maffMetaDataPromise = this.batchRequest.addURL(docUtil.resolveURL("index.rdf", this.options.baseURI || this.options.url), false);
|
|
|
+ }
|
|
|
this.maxResources = this.batchRequest.getMaxResources();
|
|
|
if (!this.options.saveRawPage && !this.options.removeFrames && this.options.framesData) {
|
|
|
this.options.framesData.forEach(frameData => this.maxResources += frameData.maxResources || 0);
|
|
|
@@ -377,6 +382,27 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
if (this.doc.head.querySelectorAll("*").length == 1 && metaCharset && this.doc.body.childNodes.length == 0) {
|
|
|
this.doc.head.querySelector("meta[charset]").remove();
|
|
|
}
|
|
|
+ if (this.maffMetaDataPromise) {
|
|
|
+ const maffMetaData = await this.maffMetaDataPromise;
|
|
|
+ if (maffMetaData && maffMetaData.content) {
|
|
|
+ const NAMESPACE_RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
|
|
|
+ const maffDoc = docUtil.parseXMLContent(maffMetaData.content);
|
|
|
+ const originalURLElement = maffDoc.querySelector("RDF > Description > originalurl");
|
|
|
+ const archiveTimeElement = maffDoc.querySelector("RDF > Description > archivetime");
|
|
|
+ if (originalURLElement) {
|
|
|
+ this.options.saveUrl = originalURLElement.getAttributeNS(NAMESPACE_RDF, "resource");
|
|
|
+ }
|
|
|
+ if (archiveTimeElement) {
|
|
|
+ const value = archiveTimeElement.getAttributeNS(NAMESPACE_RDF, "resource");
|
|
|
+ if (value) {
|
|
|
+ const date = new Date(value);
|
|
|
+ if (!isNaN(date.getTime())) {
|
|
|
+ this.options.saveDate = new Date(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
const titleElement = this.doc.querySelector("title");
|
|
|
const descriptionElement = this.doc.querySelector("meta[name=description]");
|
|
|
const authorElement = this.doc.querySelector("meta[name=author]");
|
|
|
@@ -399,8 +425,8 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
if (this.options.insertSingleFileComment) {
|
|
|
const infobarContent = (this.options.infobarContent || "").replace(/\\n/g, "\n").replace(/\\t/g, "\t");
|
|
|
const commentNode = this.doc.createComment("\n Page saved with SingleFile" +
|
|
|
- " \n url: " + this.options.url +
|
|
|
- " \n saved date: " + new Date() +
|
|
|
+ " \n url: " + this.options.saveUrl +
|
|
|
+ " \n saved date: " + this.options.saveDate +
|
|
|
(infobarContent ? " \n info: " + infobarContent : "") + "\n");
|
|
|
this.doc.documentElement.insertBefore(commentNode, this.doc.documentElement.firstChild);
|
|
|
}
|
|
|
@@ -1050,8 +1076,8 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
|
|
|
class ProcessorHelper {
|
|
|
static async evalTemplate(template = "", options, content, dontReplaceSlash) {
|
|
|
- const date = new Date();
|
|
|
- const url = docUtil.parseURL(options.url);
|
|
|
+ const date = options.saveDate;
|
|
|
+ const url = docUtil.parseURL(options.saveUrl);
|
|
|
template = await Util.evalTemplateVariable(template, "page-title", () => options.title || "No title", dontReplaceSlash);
|
|
|
template = await Util.evalTemplateVariable(template, "page-language", () => options.info.lang || "No language", dontReplaceSlash);
|
|
|
template = await Util.evalTemplateVariable(template, "page-description", () => options.info.description || "No description", dontReplaceSlash);
|