|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +module.exports.register = function () { |
| 4 | + this.on("beforePublish", ({ siteCatalog, contentCatalog, playbook }) => { |
| 5 | + const siteLink = playbook.site.url; |
| 6 | + |
| 7 | + // Find page |
| 8 | + const page = contentCatalog.findBy({ |
| 9 | + basename: "changelog.adoc", |
| 10 | + })[0]; |
| 11 | + |
| 12 | + // Get page attributes |
| 13 | + const attributes = page.asciidoc.attributes; |
| 14 | + const { |
| 15 | + productname: productName, |
| 16 | + productmajorversion: productMajorVersion, |
| 17 | + doctitle: pageTitle, |
| 18 | + description: pageDescription, |
| 19 | + docname: pageName, |
| 20 | + } = attributes; |
| 21 | + |
| 22 | + // Get page content |
| 23 | + const content = page.contents.toString(); |
| 24 | + |
| 25 | + console.log("Attributes:", attributes); |
| 26 | + console.log("Content:", content); |
| 27 | + |
| 28 | + // Create RSS feed |
| 29 | + const rss = `<?xml version="1.0" encoding="UTF-8" ?> |
| 30 | +<rss version="2.0"> |
| 31 | +
|
| 32 | +<channel> |
| 33 | + <title>${productName} ${productMajorVersion} ${pageTitle}</title> |
| 34 | + <link>${siteLink}/${pageName}</link> |
| 35 | + <description>${pageDescription}</description> |
| 36 | + <item> |
| 37 | + <title>RSS Tutorial</title> |
| 38 | + <link>https://www.w3schools.com/xml/xml_rss.asp</link> |
| 39 | + <description>New RSS tutorial on W3Schools</description> |
| 40 | + </item> |
| 41 | + <item> |
| 42 | + <title>XML Tutorial</title> |
| 43 | + <link>https://www.w3schools.com/xml</link> |
| 44 | + <description>New XML tutorial on W3Schools</description> |
| 45 | + </item> |
| 46 | +</channel> |
| 47 | +
|
| 48 | +</rss>`; |
| 49 | + |
| 50 | + // Add RSS feed to site catalog |
| 51 | + siteCatalog.addFile({ |
| 52 | + contents: Buffer.from(rss), |
| 53 | + out: { path: "rss.xml" }, |
| 54 | + }); |
| 55 | + }); |
| 56 | +}; |
0 commit comments