mirror of
https://gitea.com/gitea/docs.git
synced 2026-11-08 11:00:34 +00:00
refactor: drop the remaining docusaurus names from identifiers and comments (#589)
Follow-up to #588. - rename `DocusaurusSidebarItem` -> `SidebarSourceItem`, `fromDocusaurus` -> `fromSidebarSource`, `docusaurusSidebars` -> `sidebarSources` - reword comments and READMEs that described behaviour by comparison with docusaurus; fix the stale note in `sites/docs/src/config/api.ts` - drop `.docusaurus/` from `.gitignore` No functional change. `pnpm check` has 0 errors and `pnpm build` still builds 6690 pages. <!-- cloudflare-preview --> Preview: https://pr-589.docs-gitea-com.pages.dev Reviewed-on: https://gitea.com/gitea/docs/pulls/589 Reviewed-by: silverwind <[email protected]>
This commit is contained in:
1 parent
2275bef3bd
commit
b555a247e0
15 files changed
+46
-48
No files matched your search
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Builds one sidebar per (product, version, language) out of the loaded pages,
|
||||
* reproducing what docusaurus derived from `_category_.json` and from the
|
||||
* deriving it from `_category_.json` and from the
|
||||
* handwritten sidebar files of the runner docs.
|
||||
*/
|
||||
|
||||
@@ -44,12 +44,12 @@ export interface SidebarGroup {
|
||||
|
||||
export type SidebarEntry = SidebarLink | SidebarGroup;
|
||||
|
||||
/** A docusaurus sidebar file, as used by the runner docs. */
|
||||
export type DocusaurusSidebarItem =
|
||||
/** A hand written sidebar file, as used by the runner docs. */
|
||||
export type SidebarSourceItem =
|
||||
| string
|
||||
| { type: 'doc'; id: string; label?: string }
|
||||
| { type: 'autogenerated'; dirName: string }
|
||||
| { type: 'category'; label: string; collapsed?: boolean; items: DocusaurusSidebarItem[] };
|
||||
| { type: 'category'; label: string; collapsed?: boolean; items: SidebarSourceItem[] };
|
||||
|
||||
const last = Number.MAX_SAFE_INTEGER;
|
||||
|
||||
@@ -66,11 +66,11 @@ function labelFromDirname(name: string): string {
|
||||
|
||||
/**
|
||||
* Builds the sidebars of every group of pages, keyed by the route prefix of the
|
||||
* group. `manual` provides the docusaurus sidebar of the groups that ship one.
|
||||
* group. `manual` provides the hand written sidebar of the groups that ship one.
|
||||
*/
|
||||
export function buildSidebars(
|
||||
pages: SidebarPage[],
|
||||
manual: Map<string, DocusaurusSidebarItem[]> = new Map(),
|
||||
manual: Map<string, SidebarSourceItem[]> = new Map(),
|
||||
): Map<string, SidebarEntry[]> {
|
||||
const groups = new Map<string, SidebarPage[]>();
|
||||
for (const page of pages) {
|
||||
@@ -84,19 +84,19 @@ export function buildSidebars(
|
||||
const key = `${groupPages[0]!.meta.product}@${groupPages[0]!.meta.version}`;
|
||||
const items = manual.get(key);
|
||||
const tree = treeOf(groupPages);
|
||||
sidebars.set(prefix, items ? fromDocusaurus(items, groupPages, tree) : tree.build(''));
|
||||
sidebars.set(prefix, items ? fromSidebarSource(items, groupPages, tree) : tree.build(''));
|
||||
}
|
||||
return sidebars;
|
||||
}
|
||||
|
||||
interface Tree {
|
||||
/** Entries of a directory, ordered as docusaurus ordered them. */
|
||||
/** Entries of a directory, ordered by their position. */
|
||||
build(dir: string): SidebarEntry[];
|
||||
/** Localized label of a directory, from its `_category_.json`. */
|
||||
label(dir: string): string;
|
||||
}
|
||||
|
||||
/** Sidebar of a directory tree, ordered by `sidebar_position` as docusaurus did. */
|
||||
/** Sidebar of a directory tree, ordered by `sidebar_position`. */
|
||||
function treeOf(pages: SidebarPage[]): Tree {
|
||||
const categories = new Map<string, SidebarPage>();
|
||||
for (const page of pages) {
|
||||
@@ -148,9 +148,9 @@ function treeOf(pages: SidebarPage[]): Tree {
|
||||
return { build, label };
|
||||
}
|
||||
|
||||
/** Sidebar described by a docusaurus sidebar file, used by the runner docs. */
|
||||
function fromDocusaurus(
|
||||
items: DocusaurusSidebarItem[],
|
||||
/** Sidebar described by a hand written sidebar file, used by the runner docs. */
|
||||
function fromSidebarSource(
|
||||
items: SidebarSourceItem[],
|
||||
pages: SidebarPage[],
|
||||
tree: Tree,
|
||||
): SidebarEntry[] {
|
||||
@@ -159,7 +159,7 @@ function fromDocusaurus(
|
||||
byDocId.set([page.meta.dir, page.meta.name].filter(Boolean).join('/'), page);
|
||||
}
|
||||
|
||||
const convert = (item: DocusaurusSidebarItem): SidebarEntry | undefined => {
|
||||
const convert = (item: SidebarSourceItem): SidebarEntry | undefined => {
|
||||
if (typeof item === 'string') {
|
||||
const page = byDocId.get(item);
|
||||
return page && link(page);
|
||||
@@ -167,7 +167,7 @@ function fromDocusaurus(
|
||||
if (item.type === 'doc') {
|
||||
const page = byDocId.get(item.id);
|
||||
// the label of the sidebar file is english, the title of a translated
|
||||
// page is already localized (docusaurus translated it from the json)
|
||||
// page is already localized (translated from the json)
|
||||
return page && link(page, page.meta.locale === defaultLocale ? (item.label ?? page.title) : page.title);
|
||||
}
|
||||
if (item.type === 'autogenerated') {
|
||||
@@ -182,7 +182,7 @@ function fromDocusaurus(
|
||||
}
|
||||
|
||||
// a category whose only child is an autogenerated directory keeps the
|
||||
// translated label of the directory, like the docusaurus sidebars did
|
||||
// translated label of the directory, like the sidebar files do
|
||||
const single =
|
||||
item.items.length === 1 && typeof item.items[0] === 'object' && 'dirName' in item.items[0]
|
||||
? item.items[0]
|
||||
|
||||
Reference in new issue
Block a user