diff --git a/scripts/client.js b/scripts/client.js index bb9b8e3b..659bb41e 100644 --- a/scripts/client.js +++ b/scripts/client.js @@ -2,13 +2,11 @@ const path = require('path'); const CLIENT_PATH = path.dirname(require.resolve('@diplodoc/client')); const BUILD_PATH = 'build'; -const BUNDLE_PATH = '_bundle'; const BUNDLE_JS_FILENAME = 'app.client.js'; const BUNDLE_CSS_FILENAME = 'app.client.css'; const src = (target) => path.resolve(CLIENT_PATH, target); const dst = (target) => path.resolve(BUILD_PATH, target); -const bundle = (target) => path.join('../', BUNDLE_PATH, target); module.exports = { @@ -21,7 +19,11 @@ module.exports = { css: src(BUNDLE_CSS_FILENAME), }, bundle: { - js: bundle(BUNDLE_JS_FILENAME), - css: bundle(BUNDLE_CSS_FILENAME), + js(bundlePath) { + return path.join(bundlePath, BUNDLE_JS_FILENAME); + }, + css(bundlePath) { + return path.join(bundlePath, BUNDLE_CSS_FILENAME); + }, }, }; diff --git a/src/steps/processPages.ts b/src/steps/processPages.ts index 5feb2996..9bbec2a3 100644 --- a/src/steps/processPages.ts +++ b/src/steps/processPages.ts @@ -58,7 +58,7 @@ export async function processPages(outputBundlePath: string): Promise { })); if (singlePage) { - await saveSinglePages(); + await saveSinglePages(outputBundlePath); } } @@ -97,9 +97,10 @@ function getPathData( return pathData; } -async function saveSinglePages() { +async function saveSinglePages(outputBundlePath: string) { const { input: inputFolderPath, + output: outputFolderPath, lang, resources, } = ArgvService.getConfig(); @@ -132,10 +133,13 @@ async function saveSinglePages() { lang: lang || Lang.RU, }; + const outputTocDir = resolve(outputFolderPath, relative(inputFolderPath, tocDir)); + const relativeOutputBundlePath = relative(outputTocDir, outputBundlePath); + // Save the full single page for viewing locally const singlePageFn = join(tocDir, SINGLE_PAGE_FILENAME); const singlePageDataFn = join(tocDir, SINGLE_PAGE_DATA_FILENAME); - const singlePageContent = generateStaticMarkup(pageData); + const singlePageContent = generateStaticMarkup(pageData, relativeOutputBundlePath); writeFileSync(singlePageFn, singlePageContent); writeFileSync(singlePageDataFn, JSON.stringify(pageData)); diff --git a/src/utils/markup.ts b/src/utils/markup.ts index a0e92381..9cf7bc02 100644 --- a/src/utils/markup.ts +++ b/src/utils/markup.ts @@ -12,7 +12,7 @@ export interface TitleMeta { } export type Meta = TitleMeta & Resources; -export function generateStaticMarkup(props: DocInnerProps): string { +export function generateStaticMarkup(props: DocInnerProps, pathToBundle: string): string { const {title: metaTitle, style, script} = props.data.meta as Meta || {}; const {title: tocTitle} = props.data.toc; const {title: pageTitle} = props.data; @@ -41,7 +41,7 @@ export function generateStaticMarkup(props: DocInnerProps): string height: 100vh; } - + ${PluginService.getHeadContent()} ${resources} @@ -51,7 +51,7 @@ export function generateStaticMarkup(props: DocInnerProps): string window.STATIC_CONTENT = ${staticContent} window.__DATA__ = ${JSON.stringify(props)}; - + `;