Przeglądaj źródła

added {page-heading} template variable

Former-commit-id: d77e545e39ca82804e90a3551920ce074734725b
Gildas 6 lat temu
rodzic
commit
11ceffb452

+ 1 - 0
extension/ui/pages/help.html

@@ -462,6 +462,7 @@
 					(e.g. `{page-title}[20]` to limit the title to 20 bytes).</p>
 				<ul>
 					<li><code>{page-title}</code>: the title of the page</li>
+					<li><code>{page-heading}</code>: the content of the H1 tag in the page</li>
 					<li><code>{page-language}</code>: the language of the page</li>
 					<li><code>{page-description}</code>: the description of the page</li>
 					<li><code>{page-author}</code>: the author of the page</li>

+ 4 - 1
lib/single-file/single-file-core.js

@@ -1376,6 +1376,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			const authorElement = this.doc.querySelector("meta[name=author]");
 			const creatorElement = this.doc.querySelector("meta[name=creator]");
 			const publisherElement = this.doc.querySelector("meta[name=publisher]");
+			const headingElement = this.doc.querySelector("h1");
 			this.options.title = titleElement ? titleElement.textContent.trim() : "";
 			this.options.infobarContent = await ProcessorHelper.evalTemplate(this.options.infobarTemplate, this.options, null, true);
 			this.options.info = {
@@ -1383,7 +1384,8 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 				lang: this.doc.documentElement.lang,
 				author: authorElement && authorElement.content ? authorElement.content.trim() : "",
 				creator: creatorElement && creatorElement.content ? creatorElement.content.trim() : "",
-				publisher: publisherElement && publisherElement.content ? publisherElement.content.trim() : ""
+				publisher: publisherElement && publisherElement.content ? publisherElement.content.trim() : "",
+				heading: headingElement && headingElement.textContent ? headingElement.textContent.trim() : ""
 			};
 		}
 	}
@@ -1403,6 +1405,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			const date = options.saveDate;
 			const url = util.parseURL(options.saveUrl);
 			template = await Util.evalTemplateVariable(template, "page-title", () => options.title || "No title", dontReplaceSlash, options.filenameReplacementCharacter);
+			template = await Util.evalTemplateVariable(template, "page-heading", () => options.info.heading || "No heading", dontReplaceSlash, options.filenameReplacementCharacter);
 			template = await Util.evalTemplateVariable(template, "page-language", () => options.info.lang || "No language", dontReplaceSlash, options.filenameReplacementCharacter);
 			template = await Util.evalTemplateVariable(template, "page-description", () => options.info.description || "No description", dontReplaceSlash, options.filenameReplacementCharacter);
 			template = await Util.evalTemplateVariable(template, "page-author", () => options.info.author || "No author", dontReplaceSlash, options.filenameReplacementCharacter);