From 2890d9b2ff5edb9cc0254c07953ec5e0782e08e6 Mon Sep 17 00:00:00 2001 From: ooker Date: Thu, 11 Jul 2024 23:37:34 +0700 Subject: [PATCH] fix: og url and image have dirname in path --- lib/featured-slide.js | 5 +++-- lib/render.js | 10 ++++++---- lib/template/reveal.html | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/featured-slide.js b/lib/featured-slide.js index 469f549..73aa97b 100644 --- a/lib/featured-slide.js +++ b/lib/featured-slide.js @@ -25,7 +25,7 @@ const getSlideAnchor = featuredSlide => { export default async (initialUrl, targetDir) => { const { featuredSlide } = getOptions(); - if (!featuredSlide || !puppeteer) { + if ((!featuredSlide && featuredSlide !== 0) || !puppeteer) { return; } @@ -34,7 +34,8 @@ export default async (initialUrl, targetDir) => { const snapshotFilename = `${targetDir}/featured-slide.jpg`; const url = `http://${host}:${port}/${initialUrl}${getSlideAnchor(featuredSlide.toString())}`; - + + console.log("🚀 ~ url:", url) debug({ url, snapshotFilename, puppeteerLaunchConfig }); try { diff --git a/lib/render.js b/lib/render.js index a9bbdc5..345120d 100644 --- a/lib/render.js +++ b/lib/render.js @@ -37,7 +37,7 @@ function sanitize(entry) { * @param {Object} extraOptions - Additional options (mostly used by tests) * @returns {string} The rendered HTML compatible with reveal.js */ -export const render = async (fullMarkdown, extraOptions = {}) => { +export const render = async (fullMarkdown, extraOptions = {}, filePath = undefined) => { const { yamlOptions, markdown: contentOnlyMarkdown } = parseYamlFrontMatter(fullMarkdown); const options = Object.assign(getSlideOptions(yamlOptions), extraOptions); @@ -46,7 +46,8 @@ export const render = async (fullMarkdown, extraOptions = {}) => { const highlightThemeUrl = getHighlightThemeUrl(options.highlightTheme); const scriptPaths = getScriptPaths(options.scripts, options.assetsDir, options.base); const cssPaths = getCssPaths(options.css, options.assetsDir, options.base); - + const ogImage = filePath ? path.dirname(filePath) + '/featured-slide.jpg' : 'featured-slide.jpg' + const ogUrl = filePath.replace('.md', '.html') const revealOptions = Object.assign({}, getRevealOptions(options.revealOptions), yamlOptions.revealOptions); const slidifyOptions = _.pick(options, Object.keys(slidifyAttributeNames)); @@ -55,7 +56,6 @@ export const render = async (fullMarkdown, extraOptions = {}) => { const escaped_value = value.replace(/\n/g, '\\n').replace(/\r/g, '\\r'); slidifyAttributes.push(`${slidifyAttributeNames[key]}="${escaped_value}"`); } - const preprocessorFn = await getPreprocessor(options.preprocessor); const processedMarkdown = await preprocessorFn(contentOnlyMarkdown, options); @@ -67,6 +67,8 @@ export const render = async (fullMarkdown, extraOptions = {}) => { title, slidifyAttributes: slidifyAttributes.join(' '), markdown: processedMarkdown, + ogImage, + ogUrl, themeUrl, highlightThemeUrl, scriptPaths, @@ -83,7 +85,7 @@ export const render = async (fullMarkdown, extraOptions = {}) => { export const renderFile = async (filePath, extraOptions) => { try { const content = await readFile(filePath); - return render(content.toString(), extraOptions); + return render(content.toString(), extraOptions, filePath); } catch (e) { return render('File not found.', extraOptions); } diff --git a/lib/template/reveal.html b/lib/template/reveal.html index 2786058..ba7b244 100644 --- a/lib/template/reveal.html +++ b/lib/template/reveal.html @@ -8,8 +8,8 @@ {{#absoluteUrl}} - - + + {{/absoluteUrl}}