mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
Core: Support sync usage of getTableOfContents
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-core': patch
|
||||
---
|
||||
|
||||
Support sync usage of `getTableOfContents`
|
||||
@@ -14,7 +14,7 @@ Note: If you're using a CMS, you should use the API provided by the CMS instead.
|
||||
```ts
|
||||
import { getTableOfContents } from 'fumadocs-core/server';
|
||||
|
||||
const toc = await getTableOfContents('## markdown content');
|
||||
const toc = getTableOfContents('## markdown content');
|
||||
```
|
||||
|
||||
### Output
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
"postcss": "^8.4.47",
|
||||
"tailwindcss": "^3.4.14",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"ts-morph": "^24.0.0",
|
||||
"tsconfig": "workspace:*",
|
||||
"tsx": "^4.19.2",
|
||||
"typescript": "^5.6.3"
|
||||
|
||||
+11
-15
@@ -31,24 +31,20 @@ async function checkLinks() {
|
||||
const scanned = await scanURLs({
|
||||
populate: {
|
||||
'(home)/blog/[slug]': blogFiles.map((file) => {
|
||||
const info = parseFilePath(file.path);
|
||||
const info = parseFilePath(path.relative('content/blog', file.path));
|
||||
|
||||
return { value: getSlugs(info)[2] };
|
||||
return { value: getSlugs(info)[0] };
|
||||
}),
|
||||
'docs/[...slug]': await Promise.all(
|
||||
docsFiles.map(async (file) => {
|
||||
const info = parseFilePath(file.path);
|
||||
'docs/[...slug]': docsFiles.map((file) => {
|
||||
const info = parseFilePath(path.relative('content/docs', file.path));
|
||||
|
||||
return {
|
||||
value: getSlugs(info).slice(2),
|
||||
hashes: file.data?._mdx?.mirror
|
||||
? undefined
|
||||
: (await getTableOfContents(file.content)).map((item) =>
|
||||
item.url.slice(1),
|
||||
),
|
||||
};
|
||||
}),
|
||||
),
|
||||
return {
|
||||
value: getSlugs(info),
|
||||
hashes: file.data?._mdx?.mirror
|
||||
? undefined
|
||||
: getTableOfContents(file.content).map((item) => item.url.slice(1)),
|
||||
};
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -34,22 +34,20 @@ async function checkLinks() {
|
||||
const scanned = await scanURLs({
|
||||
populate: {
|
||||
'(home)/blog/[slug]': blogFiles.map((file) => {
|
||||
const info = parseFilePath(file.path);
|
||||
const info = parseFilePath(path.relative('content/blog', file.path));
|
||||
|
||||
return { value: getSlugs(info)[2] };
|
||||
return { value: getSlugs(info)[0] };
|
||||
}),
|
||||
'docs/[[...slug]]': await Promise.all(
|
||||
docsFiles.map(async (file) => {
|
||||
const info = parseFilePath(file.path);
|
||||
'docs/[[...slug]]': docsFiles.map((file) => {
|
||||
const info = parseFilePath(path.relative('content/docs', file.path));
|
||||
|
||||
return {
|
||||
value: getSlugs(info).slice(2),
|
||||
hashes: (await getTableOfContents(file.content)).map((item) =>
|
||||
item.url.slice(1),
|
||||
),
|
||||
};
|
||||
}),
|
||||
),
|
||||
return {
|
||||
value: getSlugs(info),
|
||||
hashes: getTableOfContents(file.content).map((item) =>
|
||||
item.url.slice(1),
|
||||
),
|
||||
};
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -15,10 +15,8 @@ export type TableOfContents = TOCItemType[];
|
||||
*
|
||||
* @param content - Markdown content
|
||||
*/
|
||||
export async function getTableOfContents(
|
||||
content: string,
|
||||
): Promise<TableOfContents> {
|
||||
const result = await remark().use(remarkHeading).process(content);
|
||||
export function getTableOfContents(content: string): TableOfContents {
|
||||
const result = remark().use(remarkHeading).processSync(content);
|
||||
|
||||
if ('toc' in result.data) return result.data.toc as TableOfContents;
|
||||
|
||||
|
||||
Generated
+3
@@ -207,6 +207,9 @@ importers:
|
||||
tailwindcss-animate:
|
||||
specifier: ^1.0.7
|
||||
version: 1.0.7([email protected])
|
||||
ts-morph:
|
||||
specifier: ^24.0.0
|
||||
version: 24.0.0
|
||||
tsconfig:
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/tsconfig
|
||||
|
||||
Reference in New Issue
Block a user