This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Step 2: Construct page data from components */ | |
| for (const component of components) { | |
| const { content } = Marked.parse(component); | |
| const [matchedComponentType] = content.matchAll(COMPONENT_TYPE_PATTERN); | |
| const [, path, name] = matchedComponentType; | |
| const [matchedHtml] = content.matchAll(HTML_CONTENT_PATTERN); | |
| const [, html] = matchedHtml; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| path: "/home", | |
| name: "Home", | |
| html: '<h1 id="home">Home</h1>\n<p>Hello world!</p>\n' | |
| } | |
| { | |
| path: "/about", | |
| name: "About", | |
| html: '<h1 id="about">About</h1>\n<p>Built for learning.</p>\n' | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Step 2: Construct page data from components */ | |
| for (const component of components) { | |
| const { content } = Marked.parse(component); | |
| const [matchedComponentType] = content.matchAll(COMPONENT_TYPE_PATTERN); | |
| const [, path, name] = matchedComponentType; | |
| const [matchedHtml] = content.matchAll(HTML_CONTENT_PATTERN); | |
| const [, html] = matchedHtml; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| layout: { footer: "<p>deno-md-site</p>\n" }, | |
| pages: [ | |
| { | |
| path: "/home", | |
| name: "Home", | |
| html: '<h1 id="home">Home</h1>\n<p>Hello world!</p>\n' | |
| }, | |
| { | |
| path: "/about", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Section: Constants */ | |
| const FIRST_ITEM_INDEX = 0; | |
| const SECOND_ITEM_INDEX = 1; | |
| const COMPONENT_DELIMITER = '+++'; | |
| const COMPONENT_TYPE_PATTERN = /<\S>(.*?)\:(.*?)<\/\S>/g; | |
| const HTML_CONTENT_PATTERN = /\n(.*)/gs; | |
| const LAYOUT_PREFIX = 'layout'; | |
| const HOME_PATH = '/home'; | |
| const STYLESHEET_PATH = 'styles.css'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Step 3: Generate templates for html content */ | |
| const isHomePath = (path: string) => path === HOME_PATH; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Step 3: Generate templates for html content */ | |
| const isHomePath = (path: string) => path === HOME_PATH; | |
| const getStylesheetHref = (path: string) => { | |
| return isHomePath(path) ? STYLESHEET_PATH : `../${STYLESHEET_PATH}`; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Step 3: Generate templates for html content */ | |
| const isHomePath = (path: string) => path === HOME_PATH; | |
| const getStylesheetHref = (path: string) => { | |
| return isHomePath(path) ? STYLESHEET_PATH : `../${STYLESHEET_PATH}`; | |
| } | |
| const getFaviconSvg = (favicon: string) => ` | |
| <svg xmlns="http://www.w3.org/2000/svg"> | |
| <text y="32" font-size="32">${favicon ? favicon : '🦕'}</text> |