Skip to content

Commit

Permalink
Modifications to get remote-content to fetch versionless docs (#2642)
Browse files Browse the repository at this point in the history
* Modifications to get remote-content to fetch versionless docs

* Update remote-content tests
  • Loading branch information
heatlikeheatwave authored Dec 3, 2024
1 parent 212c205 commit 04e040d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
8 changes: 6 additions & 2 deletions src/views/docs-view/loaders/__tests__/remote-content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('RemoteContentLoader', () => {
loader = new RemoteContentLoader({
basePath: 'commands',
product: 'waypoint',
latestVersionRef: 'v0.5.x',
})

nock.disableNetConnect()
Expand Down Expand Up @@ -67,6 +68,7 @@ describe('RemoteContentLoader', () => {
basePath: 'plugin/mux',
navDataPrefix: 'plugin-mux',
product: 'terraform-plugin-mux',
latestVersionRef: 'v0.6.x',
})

scope
Expand Down Expand Up @@ -153,7 +155,9 @@ describe('RemoteContentLoader', () => {
.get('/api/content/waypoint/nav-data/v0.5.x/commands')
.reply(200, navData_200)

const props = await loader.loadStaticProps({ params: {} })
const props = await loader.loadStaticProps({
params: { page: ['v0.5.x'] },
})

expect(props).toMatchInlineSnapshot(
{
Expand All @@ -165,7 +169,7 @@ describe('RemoteContentLoader', () => {
},
`
{
"currentPath": "",
"currentPath": "v0.5.x",
"frontMatter": {
"layout": "commands",
"page_title": "Waypoint Commands (CLI)",
Expand Down
22 changes: 4 additions & 18 deletions src/views/docs-view/loaders/remote-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ interface LoadStaticPropsReturn {
}

const moizeOpts: Options = { isPromise: true, maxSize: Infinity }
const cachedFetchNavData = moize(fetchNavData, moizeOpts)
const cachedFetchVersionMetadataList = moize(
fetchVersionMetadataList,
moizeOpts
Expand Down Expand Up @@ -147,19 +146,10 @@ export default class RemoteContentLoader implements DataLoader {
loadStaticPaths = async (): Promise<
{ params: Record<string, string[]> }[]
> => {
// Fetch version metadata to get "latest"
const versionMetadataList = await cachedFetchVersionMetadataList(
this.opts.product
)

const latest: string =
this.opts.latestVersionRef ??
versionMetadataList.find((e) => e.isLatest).version

const latest: string = this.opts.latestVersionRef ?? 'latest'
// Fetch and parse navigation data
const navDataResponse = await cachedFetchNavData(
const navDataResponse = await fetchNavData(
this.opts.product,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.opts.navDataPrefix!,
latest
)
Expand Down Expand Up @@ -206,10 +196,7 @@ export default class RemoteContentLoader implements DataLoader {
const versionMetadataList: VersionMetadataItem[] =
await cachedFetchVersionMetadataList(this.opts.product)

const latestVersion =
this.opts.latestVersionRef ??
versionMetadataList.find((e) => e.isLatest)?.version

const latestVersion = this.opts.latestVersionRef ?? 'latest'
let versionToFetch = latestVersion

if (this.opts.enabledVersionedDocs) {
Expand All @@ -236,9 +223,8 @@ export default class RemoteContentLoader implements DataLoader {
].join('/')

const documentPromise = fetchDocument(this.opts.product, fullPath)
const navDataPromise = cachedFetchNavData(
const navDataPromise = fetchNavData(
this.opts.product,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.opts.navDataPrefix!,
versionToFetch
)
Expand Down

0 comments on commit 04e040d

Please sign in to comment.