Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add authentication docs #471

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { defineConfig } from 'vitepress'
import typedocSidebar from '../content/typedoc/typedoc-sidebar.json'
import {withMermaid} from "vitepress-plugin-mermaid";

const apiItems = typedocSidebar.filter((item: any) => !['helpers', 'internal', 'gewis'].includes(item.text.toLowerCase()));
const internalsItems = typedocSidebar.filter((item: any) => ['helpers', 'internal', 'gewis'].includes(item.text.toLowerCase()));

export default defineConfig({
export default withMermaid({
title: "SudoSOS Backend",
srcDir: "./content",
base: "/docs/",
Expand Down
1 change: 1 addition & 0 deletions docs/content/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Wow!
21 changes: 21 additions & 0 deletions docs/content/typedoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,25 @@ The VitePress configuration is straightforward. Most of the custom settings are

---

### Mermaid Diagrams

We use the [vitepress-plugin-mermaid](https://github.com/emersonbottero/vitepress-plugin-mermaid) plugin to render [mermaid.js](https://mermaid.js.org/) diagrams in our documentation. To use this plugin, simply add the following (example) code block to the tsdoc comment:

```ts
/**
* ```mermaid
* graph TD
* a --> b
* ```
*/
```

This will render the following diagram:

```mermaid
graph TD
a --> b
```
---

By adhering to these guidelines and making use of the tools mentioned, we can maintain high-quality documentation that is easy to navigate and continuously updated as the codebase evolves.
102 changes: 102 additions & 0 deletions docs/plugins/typedoc-plugin-markdown-promote-docs.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { RendererEvent } from 'typedoc';
import { readFileSync, writeFileSync, existsSync } from 'fs';
import { join } from 'path';
import { MarkdownPageEvent } from 'typedoc-plugin-markdown';

const PROMOTE_TAG = '@promote';
const INDEX_TAG = '@index';

// Record promoted pages (name plus optional index).
const toPromote = [];

export function load(app) {
// Record pages marked with @promote (and optionally @index)
app.renderer.on(MarkdownPageEvent.BEGIN, (page) => {
const hasPromoteTag =
page.model.comment &&
page.model.comment.blockTags &&
page.model.comment.blockTags.some((tag) => tag.tag === PROMOTE_TAG);
if (!hasPromoteTag) return;

let promoteIndex;
const indexTag =
page.model.comment &&
page.model.comment.blockTags &&
page.model.comment.blockTags.find((tag) => tag.tag === INDEX_TAG);
if (indexTag && indexTag.content.length > 0) {
const parsed = parseInt(indexTag.content[0].text, 10);
if (!isNaN(parsed)) {
promoteIndex = parsed;
}
}
app.logger.info(`Promoting ${page.model.name} with index ${promoteIndex}`);
toPromote.push({ name: page.model.name, index: promoteIndex });

page.model.comment.blockTags = page.model.comment.blockTags.filter(
(tag) => tag.tag !== PROMOTE_TAG && tag.tag !== INDEX_TAG
);
});

// After rendering, adjust the sidebar.
app.renderer.on(RendererEvent.END, () => {
const outputDir = app.options.getValue('out');
const sidebarPath = join(outputDir, 'typedoc-sidebar.json');

if (!existsSync(sidebarPath)) {
app.logger.error(`Sidebar not found at: ${sidebarPath}`);
return;
}

try {
const sidebar = JSON.parse(readFileSync(sidebarPath, 'utf-8'));

// Helper: get promote data by name.
function getPromoteData(name) {
return toPromote.find((entry) => entry.name === name);
}

/**
* Recursively traverse the sidebar items and promote matching items one level higher.
* @param {Array} currentItems - The array of items to process.
* @param {Array} parentContainer - The container array in which the currentItems reside.
*/
function recursivelyPromote(currentItems, parentContainer) {
if (!Array.isArray(currentItems)) return;
const itemsToPromote = [];
for (let i = currentItems.length - 1; i >= 0; i--) {
const item = currentItems[i];
const promoteData = getPromoteData(item.text);
if (promoteData) {
const removed = currentItems.splice(i, 1)[0];
removed.promoteIndex = promoteData.index;
itemsToPromote.push(removed);
} else if (item.items && Array.isArray(item.items)) {
recursivelyPromote(item.items, currentItems);
}
}
if (itemsToPromote.length > 0 && parentContainer) {
// Sort promoted items by promoteIndex (items without an index go last)
itemsToPromote.sort((a, b) => {
const indexA = a.promoteIndex !== undefined ? a.promoteIndex : Infinity;
const indexB = b.promoteIndex !== undefined ? b.promoteIndex : Infinity;
return indexA - indexB;
});
// Insert them into the parent container (i.e. one level higher)
parentContainer.unshift(...itemsToPromote);
}
}

if (Array.isArray(sidebar)) {
// For each top-level section, promote nested items one level higher.
sidebar.forEach((section) => {
if (section.items && Array.isArray(section.items)) {
recursivelyPromote(section.items, sidebar);
}
});
}
writeFileSync(sidebarPath, JSON.stringify(sidebar, null, 2));
} catch (error) {
app.logger.error(`Error modifying sidebar: ${error.message}`);
}
});
}
Loading
Loading