Skip to content

Commit

Permalink
fix: Fix missed toc data for static-content
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Nov 13, 2024
1 parent 8ce0c12 commit 257f2fe
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
12 changes: 7 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@
]
},
"dependencies": {
"@diplodoc/client": "^3.1.6",
"@diplodoc/client": "^3.1.8",
"@diplodoc/translation": "^1.4.3",
"csp-header": "^5.2.1",
"katex": "^0.16.9",
"shelljs": "0.8.5",
"threads": "1.7.0",
Expand Down Expand Up @@ -90,6 +89,7 @@
"axios": "^1.6.7",
"chalk": "^4.1.2",
"commander": "^12.0.0",
"csp-header": "^5.2.1",
"esbuild": "^0.23.1",
"glob": "^8.0.3",
"html-escaper": "^3.0.3",
Expand Down
16 changes: 13 additions & 3 deletions src/pages/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
DEFAULT_CSP_SETTINGS,
RTL_LANGS,
} from '../constants';
import {LeadingPage, Resources, TextItems, VarsMetadata} from '../models';
import {LeadingPage, Resources, TextItems, VarsMetadata, YfmToc} from '../models';
import {ArgvService, PluginService} from '../services';
import {getDepthPath} from '../utils';

Expand All @@ -26,16 +26,26 @@ export type Meta = TitleMeta &
metadata: VarsMetadata;
};

type TocInfo = {
content: YfmToc;
path: string;
};

export function generateStaticMarkup(
props: DocInnerProps<DocPageData>,
tocPath: string,
toc: TocInfo,
title: string,
): string {
/* @todo replace rest operator with proper unpacking */
const {style, script, csp, metadata, ...restYamlConfigMeta} = (props.data.meta as Meta) || {};
const resources = getResources({style, script});

const {staticContent} = ArgvService.getConfig();
if (staticContent) {
// TODO: there shoul be two different types YfmToc and YfmProcessedToc
// @ts-ignore
props.data.toc = toc.content;
}

const depth = props.router.depth;
const html = staticContent ? render(props) : '';
Expand Down Expand Up @@ -71,7 +81,7 @@ export function generateStaticMarkup(
window.STATIC_CONTENT = ${staticContent}
window.__DATA__ = ${JSON.stringify(props)};
</script>
<script src="${tocPath + '.js'}" type="application/javascript"></script>
<script src="${toc.path + '.js'}" type="application/javascript"></script>
${manifest.app.js
.map((url: string) => join(BUNDLE_FOLDER, url))
.map(
Expand Down
6 changes: 5 additions & 1 deletion src/resolvers/md2html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ export async function resolveMd2HTML(options: ResolverOptions): Promise<DocInner
const [tocDir, toc] = TocService.getForPath(inputPath) as [string, YfmToc];

const title = getTitle(toc.title as string, props.data.title);
const outputFileContent = generateStaticMarkup(props, join(tocDir, 'toc'), title);
const tocInfo = {
content: toc,
path: join(tocDir, 'toc'),
};
const outputFileContent = generateStaticMarkup(props, tocInfo, title);
writeFileSync(outputPath, outputFileContent);
logger.info(inputPath, PROCESSING_FINISHED);

Expand Down
2 changes: 1 addition & 1 deletion src/steps/processPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ async function saveSinglePages() {
const singlePageDataFn = join(tocDir, SINGLE_PAGE_DATA_FILENAME);
const singlePageContent = generateStaticMarkup(
pageData,
join(relativeTocDir, 'single-page-toc'),
{path: join(relativeTocDir, 'single-page-toc'), content: toc},
(toc.title as string) || '',
);

Expand Down

0 comments on commit 257f2fe

Please sign in to comment.