Skip to content

Commit 829a72e

Browse files
authored
build script - add a new sourceFile item to frontmatter (#2719)
1 parent 0d5aa9d commit 829a72e

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

scripts/build-docs.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ description: This is a simple test page
227227
lastUpdated: ${initialCommitDate.toISOString()}
228228
sdkScoped: "false"
229229
canonical: /docs/simple-test
230+
sourceFile: /docs/simple-test.mdx
230231
---
231232
232233
# Simple Test Page
@@ -1664,6 +1665,7 @@ canonical: /docs/references/react/guide
16641665
availableSdks: react
16651666
notAvailableSdks: ""
16661667
activeSdk: react
1668+
sourceFile: /docs/references/react/guide.mdx
16671669
---
16681670
16691671
# React Guide
@@ -1730,6 +1732,7 @@ canonical: /docs/guide
17301732
availableSdks: react
17311733
notAvailableSdks: ""
17321734
activeSdk: react
1735+
sourceFile: /docs/guide.mdx
17331736
---
17341737
17351738
# React Guide
@@ -1791,6 +1794,7 @@ title: API Documentation
17911794
description: x
17921795
sdkScoped: "false"
17931796
canonical: /docs/api-doc
1797+
sourceFile: /docs/api-doc.mdx
17941798
---
17951799
17961800
# API Documentation
@@ -1859,6 +1863,7 @@ canonical: /docs/quickstarts/nextjs-pages-router
18591863
availableSdks: nextjs
18601864
notAvailableSdks: react
18611865
activeSdk: nextjs
1866+
sourceFile: /docs/quickstarts/nextjs-pages-router.mdx
18621867
---
18631868
18641869
# Next.js Quickstart (Pages Router)
@@ -3862,6 +3867,7 @@ canonical: /docs/doc-2
38623867
availableSdks: react
38633868
notAvailableSdks: ""
38643869
activeSdk: react
3870+
sourceFile: /docs/doc-2.mdx
38653871
---
38663872
38673873
[Link to doc 1](/docs/doc-1)
@@ -4149,6 +4155,7 @@ title: Doc 2
41494155
description: x
41504156
sdkScoped: "false"
41514157
canonical: /docs/doc-2
4158+
sourceFile: /docs/doc-2.mdx
41524159
---
41534160
41544161
<Cards>
@@ -4229,6 +4236,7 @@ canonical: /docs/:sdk:/guide-2
42294236
availableSdks: react,nextjs
42304237
notAvailableSdks: ""
42314238
activeSdk: nextjs
4239+
sourceFile: /docs/guide-2.nextjs.mdx
42324240
---
42334241
42344242
<SDKLink href="/docs/guide-1" sdks={["react"]}>Link</SDKLink>
@@ -6478,6 +6486,7 @@ canonical: /docs/:sdk:/doc-2
64786486
availableSdks: expo,nextjs
64796487
notAvailableSdks: react
64806488
activeSdk: expo
6489+
sourceFile: /docs/doc-2.mdx
64816490
---
64826491
64836492
<SDKLink href="/docs/reference/react/doc-1" sdks={["react"]}>Doc 1</SDKLink>
@@ -6623,6 +6632,7 @@ title: API Documentation
66236632
description: Generated API docs
66246633
sdkScoped: "false"
66256634
canonical: /docs/api-doc
6635+
sourceFile: /docs/api-doc.mdx
66266636
---
66276637
66286638
# API Documentation
@@ -6692,6 +6702,7 @@ canonical: /docs/:sdk:/api-doc
66926702
availableSdks: nextjs,remix,react
66936703
notAvailableSdks: ""
66946704
activeSdk: nextjs
6705+
sourceFile: /docs/api-doc.mdx
66956706
---
66966707
66976708
Documentation specific to Next.js and Remix
@@ -6706,6 +6717,7 @@ canonical: /docs/:sdk:/api-doc
67066717
availableSdks: nextjs,remix,react
67076718
notAvailableSdks: ""
67086719
activeSdk: remix
6720+
sourceFile: /docs/api-doc.mdx
67096721
---
67106722
67116723
Documentation specific to Next.js and Remix
@@ -6720,6 +6732,7 @@ sdk: nextjs, remix, react
67206732
availableSdks: nextjs,remix,react
67216733
notAvailableSdks: ""
67226734
activeSdk: react
6735+
sourceFile: /docs/api-doc.react.mdx
67236736
---
67246737
67256738
Documentation specific to React.js
@@ -6803,6 +6816,7 @@ canonical: /docs/:sdk:/test
68036816
availableSdks: react,nextjs
68046817
notAvailableSdks: ""
68056818
activeSdk: nextjs
6819+
sourceFile: /docs/test.nextjs.mdx
68066820
---
68076821
68086822
Documentation specific to Next.js
@@ -6816,6 +6830,7 @@ canonical: /docs/:sdk:/test
68166830
availableSdks: react,nextjs
68176831
notAvailableSdks: ""
68186832
activeSdk: react
6833+
sourceFile: /docs/test.mdx
68196834
---
68206835
68216836
Documentation specific to React
@@ -6897,6 +6912,7 @@ title: Overview
68976912
description: x
68986913
sdkScoped: "false"
68996914
canonical: /docs/overview
6915+
sourceFile: /docs/overview.mdx
69006916
---
69016917
69026918
<SDKLink href="/docs/:sdk:/api-doc" sdks={["nextjs","remix","react"]}>API Doc</SDKLink>
@@ -6965,6 +6981,7 @@ sdk: nextjs, remix, react
69656981
availableSdks: nextjs,remix,react
69666982
notAvailableSdks: ""
69676983
activeSdk: react
6984+
sourceFile: /docs/api-doc.react.mdx
69686985
---
69696986
69706987
Documentation specific to React.js
@@ -6994,6 +7011,7 @@ sdk: nextjs, remix, react
69947011
availableSdks: nextjs,remix,react
69957012
notAvailableSdks: ""
69967013
activeSdk: react
7014+
sourceFile: /docs/api-doc.react.mdx
69977015
---
69987016
69997017
Updated Documentation specific to React.js
@@ -7192,14 +7210,15 @@ title: API Documentation
71927210
description: x
71937211
sdkScoped: "false"
71947212
canonical: /docs/api-doc
7213+
sourceFile: /docs/api-doc.mdx
71957214
---
71967215
71977216
<Tooltip><TooltipTrigger>Tooltip</TooltipTrigger><TooltipContent>React.js is a framework or a library idk</TooltipContent></Tooltip>
71987217
`)
71997218
})
72007219

72017220
test('Should validate links in tooltips', async () => {
7202-
const { tempDir, readFile } = await createTempFiles([
7221+
const { tempDir } = await createTempFiles([
72037222
{
72047223
path: './docs/manifest.json',
72057224
content: JSON.stringify({

scripts/build-docs.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@ export async function build(config: BuildConfig, store: Store = createBlankStore
880880
lastUpdated: (await getCommitDate(doc.file.fullFilePath))?.toISOString() ?? undefined,
881881
sdkScoped: 'false',
882882
canonical: doc.file.href,
883+
sourceFile: `/docs/${doc.file.filePathInDocsFolder}`,
883884
}),
884885
)
885886
.process(doc.vfile),
@@ -991,17 +992,22 @@ ${yaml.stringify({
991992
if (doc.file.filePathInDocsFolder.endsWith(`.${targetSdk}.mdx`)) return null
992993

993994
// if the doc has distinct version, we want to use those instead of the "generic" sdk scoped version
994-
const fileContent = (() => {
995+
const { fileContent, sourceFile } = (() => {
995996
if (doc.distinctSDKVariants?.includes(targetSdk)) {
996997
const distinctSDKVariant = docsMap.get(`${doc.file.href}.${targetSdk}`)
997998

998-
if (distinctSDKVariant === undefined) return doc.fileContent
999-
1000-
return distinctSDKVariant.fileContent
999+
if (distinctSDKVariant !== undefined) {
1000+
return {
1001+
fileContent: distinctSDKVariant.fileContent,
1002+
sourceFile: `/docs/${distinctSDKVariant.file.filePathInDocsFolder}`,
1003+
}
1004+
}
1005+
}
1006+
return {
1007+
fileContent: doc.fileContent,
1008+
sourceFile: `/docs/${doc.file.filePathInDocsFolder}`,
10011009
}
1002-
return doc.fileContent
10031010
})()
1004-
10051011
const sdks = [...(doc.sdk ?? []), ...(doc.distinctSDKVariants ?? [])]
10061012

10071013
const hrefSegments = doc.file.href.split('/')
@@ -1032,6 +1038,7 @@ ${yaml.stringify({
10321038
availableSdks: sdks?.join(','),
10331039
notAvailableSdks: config.validSdks.filter((sdk) => !sdks?.includes(sdk)).join(','),
10341040
activeSdk: targetSdk,
1041+
sourceFile: sourceFile,
10351042
}),
10361043
)
10371044
.process({

0 commit comments

Comments
 (0)