-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract runtime tpl (#1883)
- Loading branch information
Showing
2 changed files
with
32 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { filesMeta, tabs } from '.'; | ||
import deepmerge from '{{{deepmerge}}}'; | ||
export const patchRoutes = ({ routes }) => { | ||
Object.values(routes).forEach((route) => { | ||
if (filesMeta[route.id]) { | ||
if (process.env.NODE_ENV === 'production' && (route.meta?.frontmatter?.debug || filesMeta[route.id].frontmatter.debug)) { | ||
// hide route in production which set hide frontmatter | ||
delete routes[route.id]; | ||
} else { | ||
// merge meta to route object | ||
route.meta = deepmerge(route.meta, filesMeta[route.id]); | ||
// apply real tab data from id | ||
route.meta.tabs = route.meta.tabs?.map((id) => { | ||
const meta = { | ||
frontmatter: { title: tabs[id].title }, | ||
toc: [], | ||
texts: [], | ||
} | ||
return { | ||
...tabs[id], | ||
meta: filesMeta[id] || meta, | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
} |