Skip to content

Commit

Permalink
#8 Отказ от рерайтов в пользу определения порядка внутри самого md фа…
Browse files Browse the repository at this point in the history
…йла документации
  • Loading branch information
sfaqer committed Oct 30, 2024
1 parent ae13868 commit c67bd76
Show file tree
Hide file tree
Showing 26 changed files with 44 additions and 9 deletions.
28 changes: 19 additions & 9 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ export default defineConfig({
// https://vitepress.dev/reference/site-config#base
base: "/docs",

rewrites(id) {
return id.replace(/\d+-/, '').replace(/\\/, '/')
},

cleanUrls: true,

locales: {
Expand Down Expand Up @@ -90,6 +86,11 @@ interface SidebarOptions {
collapsed: boolean;
}

// type _SidebarItem = DefaultTheme.SidebarItem & { order: string }
interface OrderedSidebarItem extends DefaultTheme.SidebarItem {
order: number;
}

function getSidebar({ contentRoot, contentDirs, collapsed }: SidebarOptions): DefaultTheme.SidebarItem[] {
const sidebar: DefaultTheme.SidebarItem[] = [];

Expand All @@ -113,7 +114,7 @@ function getSidebarConfig(contentRoot, contentDir, text, collapsed): DefaultThem
}

function getSidebarItems(contentRoot, contentDir): DefaultTheme.SidebarItem[] {
const sidebarItems: DefaultTheme.SidebarItem[] = [];
const sidebarItems: OrderedSidebarItem[] = [];
const cwd = `${process.cwd()}/${contentRoot}`;
const files = glob.sync(`${contentDir}/*.md`, { cwd }).sort();

Expand All @@ -123,11 +124,20 @@ function getSidebarItems(contentRoot, contentDir): DefaultTheme.SidebarItem[] {
sidebarItems.push(sidebarItem);
}

sidebarItems.sort((first, second) => {
if (first.order >= second.order) {
return 1;
} else if (second.order >= first.order) {
return -1;
} else {
return 0;
}
})

return sidebarItems;
}

function getSidebarItem(contentRoot, file): DefaultTheme.SidebarItem {
function getSidebarItem(contentRoot, file): OrderedSidebarItem {
const fileName = path.basename(file, '.md');
const pageName = fileName
.replace(/^\d+-/, '')
Expand All @@ -138,10 +148,10 @@ function getSidebarItem(contentRoot, file): DefaultTheme.SidebarItem {
const fileContent = fs.readFileSync(path.join(contentRoot, file), 'utf8');
const { data: frontmatter } = matter(fileContent);

const sidebarItem: DefaultTheme.SidebarItem = {
const sidebarItem: OrderedSidebarItem = {
text: frontmatter.title || pageName,
link: "/" + file.replace(/\d+-/, '').replace(/\\/, '/'),
// order: frontmatter.order || 0
link: "/" + file.replace(/\\/, '/'),
order: frontmatter.order || Number.MAX_VALUE
};

return sidebarItem;
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/additional-processing.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Дополнительная обработка компонента
order: 150
---

# Дополнительная обработка компонента
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/aliases-grouping.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Группировка компонентов по алиасу
order: 220
---

# Группировка компонентов по алиасу
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/aliases.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Алиасы компонентов
order: 90
---

# Алиасы компонентов
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/annotation-inheritance.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Наследование аннотаций
order: 200
---

# Наследование аннотаций
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/annotations-processing.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Обработка аннотаций
order: 210
---

# Обработка аннотаций
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/app-context.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Использование контекста приложения
order: 160
---

# Использование контекста приложения
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/app-settings-injection.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Внедрение настроек приложения
order: 60
---

# Внедрение настроек приложения
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/component-declaration.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Объявление компонента
order: 10
---

# Объявление компонента
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/component-instance.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Получение экземпляра компонента
order: 20
---

# Получение экземпляра компонента
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/component-overriding.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Переопределение компонента по имени
order: 120
---

# Переопределение компонента по имени
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/component-post-initialization.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Пост-инициализация компонента
order: 130
---

# Пост-инициализация компонента
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/component-uniqueness.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Уникальность экземпляров компонентов
order: 140
---

# Уникальность экземпляров компонентов
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/components-binding.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Связывание компонентов между собой
order: 30
---

# Связывание компонентов между собой
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/components-factory.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Фабрика компонентов
order: 40
---

# Фабрика компонентов
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/components-prioritization.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Приоритизация компонентов с общим алиасом
order: 110
---

# Приоритизация компонентов с общим алиасом
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/components-sorting.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Упорядочивание компонентов при получении в виде сортированных коллекций
order: 100
---

# Упорядочивание компонентов при получении в виде сортированных коллекций
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/conditional-registration.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Условная регистрация компонентов в контексте приложения
order: 170
---

# Условная регистрация компонентов в контексте приложения
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/custom-annotations.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Собственные аннотации
order: 190
---

# Собственные аннотации
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/custom-arguments.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Произвольные аргументы конструктора
order: 80
---

# Произвольные аргументы конструктора
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/dependency-injection.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Внедрение зависимостей в поля и функции-сеттеры
order: 50
---

# Внедрение зависимостей в поля и функции-сеттеры
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/instance-generator.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Генератор экземпляров компонентов
order: 70
---

# Генератор экземпляров компонентов
Expand Down
1 change: 1 addition & 0 deletions docs/framework-elements/launch-control-inversion.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Инверсия управления запуском приложения
order: 180
---

# Инверсия управления запуском приложения
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Что такое Autumn?
order: 10
---

![autumn](../static/cover.png)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Дополнительные пакеты Autumn
order: 30
---

# Модули и пакеты
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Первое приложение
order: 20
---

<!-- TODO: Тут должен быть какой-то заголовок с #, иначе рендерится некрасиво -->
Expand Down

0 comments on commit c67bd76

Please sign in to comment.