Skip to content

Commit 251aff0

Browse files
committed
fix: try to fix broken doc pages
1 parent 8ea2c52 commit 251aff0

File tree

6 files changed

+344
-80
lines changed

6 files changed

+344
-80
lines changed

pwa/api/contributors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const octokit = new MyOctokit({
3232
onRateLimit: (
3333
retryAfter: number,
3434
options: Options,
35-
_octokit,
35+
_octokit: any,
3636
retryCount: number
3737
) => {
3838
console.warn(

pwa/api/doc/index.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import matter from "gray-matter";
44
import { extractHeadingsFromMarkdown, slugify } from "utils";
55
import { Octokit } from "octokit";
66
import { throttling } from "@octokit/plugin-throttling";
7-
import { Lang, getHighlighter } from "shiki";
7+
import { Lang } from "shiki";
88
import YAML from "yaml";
99
import MarkdownIt from "markdown-it";
1010
import { cache } from "react";
1111
import { current } from "consts";
1212
import { Chapters } from "types";
13+
import { getOrCreateHighlighter, highlightCode } from "utils/highlighter";
1314

1415
export const MyOctokit = Octokit.plugin(throttling);
1516
const sidebarMemoryCache = new Map();
@@ -144,6 +145,7 @@ const imgRegex = /<img([^>]*)src="([^"]+)"([^>]*)>/g;
144145
const linkRegex = /<a([^>]*)href="([^"]+)"([^>]*)>/g;
145146

146147
const headingRegex = /<h([2-4])>(.*?)<\/h\1>/gm;
148+
const codeBlockWithoutLangRegex = /(?:^|\n) {4}(\$|#)(.*(?:\n {4}.+)*)/g;
147149

148150
function getLang(block: string): string {
149151
const language = block.match(codeLanguage);
@@ -168,27 +170,12 @@ export const getHtmlFromGithubContent = async (
168170
typographer: true,
169171
});
170172

171-
const highlighter = await getHighlighter({
172-
themes: ["github-light", "one-dark-pro"],
173-
});
174-
const languages = highlighter.getLoadedLanguages();
175-
176-
const highlightCode = (code: string, language: string) => {
177-
language = language.toLowerCase();
178-
const langExists = languages.includes(language as Lang);
179-
180-
const lang = langExists ? language : "shell";
181-
182-
return (
183-
highlighter.codeToHtml(code, { lang, theme: "one-dark-pro" }) +
184-
highlighter.codeToHtml(code, { lang, theme: "github-light" })
185-
);
186-
};
173+
await getOrCreateHighlighter();
187174

188175
md.options.highlight = highlightCode;
189176

190177
// convert code selectors
191-
const transformCodeBlocks = (markdown: string) => {
178+
const transformCodeSelectors = (markdown: string) => {
192179
{
193180
const matches = markdown.match(codeInside);
194181

@@ -235,7 +222,10 @@ export const getHtmlFromGithubContent = async (
235222
}
236223
};
237224

238-
const transformedMarkdown = transformCodeBlocks(result);
225+
const transformedMarkdown = transformCodeSelectors(result)
226+
.replace(codeBlockWithoutLangRegex, "\n```\n$1$2\n```\n") // convert codeblocks with indentation into classic codeblocks
227+
.replace(/^(?: {4})/gm, "");
228+
239229
return md
240230
.render(transformedMarkdown)
241231
.replace(

pwa/app/(common)/docs/[...slug]/page.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ export async function generateStaticParams() {
3535
return slugs;
3636
}
3737

38-
export const dynamicParams = false;
39-
4038
export default async function Page({
4139
params: { slug },
4240
}: {

pwa/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"remark-frontmatter": "^4.0.1",
3737
"remark-mdx-frontmatter": "^3.0.0",
3838
"sharp": "^0.32.1",
39-
"shiki": "^0.14.2",
39+
"shiki": "^0.14.3",
4040
"unist-util-visit": "^4.1.2",
4141
"yaml": "^2.3.1"
4242
},

0 commit comments

Comments
 (0)