11'use strict'
22
33const { NodeHtmlMarkdown } = require ( 'node-html-markdown' )
4+ const YAML = require ( 'yaml' )
45
56let nhm
67const customTranslators = {
@@ -12,8 +13,8 @@ const customTranslators = {
1213
1314 const type = ( node
1415 . classList . values ( ) .
15- find ( v => v != 'admonitionblock' )
16- . toUpperCase ( ) )
16+ find ( v => v != 'admonitionblock' ) || 'NOTE'
17+ ) . toUpperCase ( )
1718
1819 const content = (
1920 nhm . translate (
@@ -30,16 +31,28 @@ nhm = new NodeHtmlMarkdown({}, customTranslators)
3031
3132const File = require ( 'vinyl' )
3233
33- function markdownify ( page ) {
34+ function markdownify ( page , pubDate ) {
35+ const title = page . title
3436 const html = page . contents . toString ( )
37+ const markdown = nhm . translate ( html )
3538
3639 // haha, we now have to translate the .md link back to .html just for this link
3740 const orig = page . pub . url . replace ( / \. m d $ / , '.html' )
38- const link = `[View original HTML](${ orig } )\n\n`
3941
40- const markdown = link + nhm . translate ( html )
42+ let output =
43+ `[View original HTML](${ orig } )\n\n` +
44+ `# ${ title } \n\n${ markdown } `
4145
42- page . contents = Buffer . from ( markdown )
46+ const frontmatter = {
47+ title,
48+ description : page . asciidoc . attributes . description ,
49+ editUrl : page . src . editUrl ,
50+ pubDate,
51+ }
52+
53+ output = `---\n${ YAML . stringify ( frontmatter ) } ---\n\n${ output } `
54+
55+ page . contents = Buffer . from ( output )
4356}
4457
4558module . exports . register = function ( { playbook, config } ) {
@@ -84,6 +97,8 @@ module.exports.register = function ({ playbook, config }) {
8497 this . once ( 'documentsConverted' , async ( { playbook, contentCatalog, siteCatalog } ) => {
8598 const logger = this . getLogger ( 'llm-summaries' )
8699
100+ const pubDate = new Date ( ) . toISOString ( )
101+
87102 const pages = contentCatalog . getPages (
88103 ( page ) =>
89104 page . mediaType === 'text/html'
@@ -92,7 +107,7 @@ module.exports.register = function ({ playbook, config }) {
92107
93108 for ( const page of pages ) {
94109 page . mediaType = 'text/markdown'
95- markdownify ( page )
110+ markdownify ( page , pubDate )
96111 }
97112 } )
98113
0 commit comments