feat: Add treefmt #4
|
@ -1,25 +1,25 @@
|
||||||
import { defineConfig } from 'astro/config';
|
import { defineConfig } from "astro/config";
|
||||||
|
|
||||||
import rehypeSanitize from 'rehype-sanitize';
|
import rehypeSanitize from "rehype-sanitize";
|
||||||
import rehypeStringify from 'rehype-stringify';
|
import rehypeStringify from "rehype-stringify";
|
||||||
import rehypeRaw from 'rehype-raw';
|
import rehypeRaw from "rehype-raw";
|
||||||
import remarkParse from 'remark-parse';
|
import remarkParse from "remark-parse";
|
||||||
import remarkRehype from 'remark-rehype';
|
import remarkRehype from "remark-rehype";
|
||||||
|
|
||||||
// https://astro.build/config
|
// https://astro.build/config
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
markdown: {
|
markdown: {
|
||||||
remarkRehype: {
|
remarkRehype: {
|
||||||
allowDangerousHtml: true
|
allowDangerousHtml: true,
|
||||||
// This is fine because we are using rehypeSanitize to sanitize XSS.
|
// This is fine because we are using rehypeSanitize to sanitize XSS.
|
||||||
// See https://github.com/remarkjs/remark-rehype?tab=readme-ov-file#example-supporting-html-in-markdown-properly
|
// See https://github.com/remarkjs/remark-rehype?tab=readme-ov-file#example-supporting-html-in-markdown-properly
|
||||||
},
|
},
|
||||||
remarkPlugins: [
|
remarkPlugins: [
|
||||||
remarkParse,
|
remarkParse,
|
||||||
remarkRehype,
|
remarkRehype,
|
||||||
rehypeRaw,
|
rehypeRaw,
|
||||||
rehypeSanitize,
|
rehypeSanitize,
|
||||||
rehypeStringify,
|
rehypeStringify,
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
15
flake.nix
15
flake.nix
|
@ -28,11 +28,14 @@
|
||||||
namespace = "auxolotl--docs-site";
|
namespace = "auxolotl--docs-site";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs-builder = channels: let
|
outputs-builder =
|
||||||
treefmt = inputs.treefmt-nix.lib.evalModule channels.nixpkgs ./treefmt.nix;
|
channels:
|
||||||
in {
|
let
|
||||||
formatter = treefmt.config.build.wrapper;
|
treefmt = inputs.treefmt-nix.lib.evalModule channels.nixpkgs ./treefmt.nix;
|
||||||
checks.formatting = treefmt.config.build.check inputs.self;
|
in
|
||||||
};
|
{
|
||||||
|
formatter = treefmt.config.build.wrapper;
|
||||||
|
checks.formatting = treefmt.config.build.check inputs.self;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,4 @@ const { Content } = await post.render();
|
||||||
|
|
||||||
<div class="contents">
|
<div class="contents">
|
||||||
<Content />
|
<Content />
|
||||||
</div>
|
</div>s
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,162 +2,181 @@ import type { CollectionEntry } from "astro:content";
|
||||||
import { parse, join, sep } from "node:path";
|
import { parse, join, sep } from "node:path";
|
||||||
|
|
||||||
export interface PageLinkData {
|
export interface PageLinkData {
|
||||||
id: string;
|
id: string;
|
||||||
data: { title: string; };
|
data: { title: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
type AllPathInformation = Map<string, CollectionEntry<"wiki"> | null>;
|
type AllPathInformation = Map<string, CollectionEntry<"wiki"> | null>;
|
||||||
|
|
||||||
export interface Paths {
|
export interface Paths {
|
||||||
siblingPages: PageLinkData[];
|
siblingPages: PageLinkData[];
|
||||||
siblingDirectories: PageLinkData[];
|
siblingDirectories: PageLinkData[];
|
||||||
childPages: PageLinkData[];
|
childPages: PageLinkData[];
|
||||||
childDirectories: PageLinkData[];
|
childDirectories: PageLinkData[];
|
||||||
|
|
||||||
parentDirectory: PageLinkData | null;
|
parentDirectory: PageLinkData | null;
|
||||||
currentPage: PageLinkData;
|
currentPage: PageLinkData;
|
||||||
};
|
|
||||||
|
|
||||||
export function relativePagePaths(wikiEntries: PageLinkData[], currentPath: string): Paths {
|
|
||||||
let currentPage: PageLinkData | undefined;
|
|
||||||
let parentDirectory: PageLinkData | undefined | null;
|
|
||||||
const siblingPages: Map<string, PageLinkData> = new Map();
|
|
||||||
const childPages: Map<string, PageLinkData> = new Map();
|
|
||||||
|
|
||||||
const currentPathParsed = parse(currentPath);
|
|
||||||
const currentPathExtensionless = join(currentPathParsed.dir, currentPathParsed.name);
|
|
||||||
|
|
||||||
const childDirectoryPaths: Set<string> = new Set();
|
|
||||||
const siblingDirectoryPaths: Set<string> = new Set();
|
|
||||||
|
|
||||||
for (const entry of wikiEntries) {
|
|
||||||
const pagePathParsed = parse(entry.id);
|
|
||||||
const pagePathExtensionless = join(pagePathParsed.dir, pagePathParsed.name);
|
|
||||||
|
|
||||||
if (pagePathExtensionless === currentPathExtensionless) {
|
|
||||||
currentPage = entry
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isInCurrentDirectory = pagePathParsed.dir === currentPathParsed.dir;
|
|
||||||
if (isInCurrentDirectory) {
|
|
||||||
siblingPages.set(pagePathExtensionless, entry);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isDirectChild = pagePathParsed.dir === currentPathExtensionless;
|
|
||||||
if (isDirectChild) {
|
|
||||||
childPages.set(pagePathExtensionless, entry);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isIndirectChild = pagePathParsed.dir.startsWith(currentPathExtensionless + sep);
|
|
||||||
if (isIndirectChild) {
|
|
||||||
const nextPathSeparator = pagePathParsed.dir.indexOf(sep, currentPathExtensionless.length + 1);
|
|
||||||
|
|
||||||
if (nextPathSeparator === -1) {
|
|
||||||
childDirectoryPaths.add(pagePathParsed.dir);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
childDirectoryPaths.add(pagePathParsed.dir.slice(0, nextPathSeparator));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isIndirectInCurrentDirectory = currentPathParsed.dir === "" || pagePathParsed.dir.startsWith(currentPathParsed.dir + sep);
|
|
||||||
if (isIndirectInCurrentDirectory) {
|
|
||||||
const nextPathSeparator = pagePathParsed.dir.indexOf(sep, currentPathParsed.dir.length + 1);
|
|
||||||
|
|
||||||
if (nextPathSeparator === -1) {
|
|
||||||
siblingDirectoryPaths.add(pagePathParsed.dir);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
siblingDirectoryPaths.add(pagePathParsed.dir.slice(0, nextPathSeparator));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isParentDirectory = pagePathExtensionless === currentPathParsed.dir;
|
|
||||||
if (isParentDirectory) {
|
|
||||||
parentDirectory = entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const childDirectories: PageLinkData[] = [];
|
|
||||||
for (const childDirectoryPath of childDirectoryPaths.values()) {
|
|
||||||
const childDirectoryPage = childPages.get(childDirectoryPath);
|
|
||||||
if (childDirectoryPage) {
|
|
||||||
childDirectories.push(childDirectoryPage);
|
|
||||||
childPages.delete(childDirectoryPath);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const childDirectoryPathParsed = parse(childDirectoryPath);
|
|
||||||
childDirectories.push({
|
|
||||||
id: childDirectoryPath,
|
|
||||||
data: { title: childDirectoryPathParsed.name }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const siblingDirectories: PageLinkData[] = [];
|
|
||||||
for (const siblingDirectoryPath of siblingDirectoryPaths.values()) {
|
|
||||||
const siblingDirectoryPage = siblingPages.get(siblingDirectoryPath);
|
|
||||||
if (siblingDirectoryPage) {
|
|
||||||
siblingDirectories.push(siblingDirectoryPage);
|
|
||||||
siblingPages.delete(siblingDirectoryPath);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const siblingDirectoryPathParsed = parse(siblingDirectoryPath);
|
|
||||||
siblingDirectories.push({
|
|
||||||
id: siblingDirectoryPath,
|
|
||||||
data: { title: siblingDirectoryPathParsed.name }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentPage === undefined) {
|
|
||||||
currentPage = {
|
|
||||||
id: currentPath,
|
|
||||||
data: { title: currentPathParsed.name }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parentDirectory === undefined) {
|
|
||||||
if (currentPathParsed.dir) {
|
|
||||||
const parentDirectoryPathParsed = parse(currentPathParsed.dir);
|
|
||||||
parentDirectory = {
|
|
||||||
id: currentPathParsed.dir,
|
|
||||||
data: { title: parentDirectoryPathParsed.name }
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
parentDirectory = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
siblingPages: Array.from(siblingPages.values()).sort(),
|
|
||||||
childPages: Array.from(childPages.values()).sort(),
|
|
||||||
|
|
||||||
siblingDirectories: siblingDirectories.sort(),
|
|
||||||
childDirectories: childDirectories.sort(),
|
|
||||||
|
|
||||||
currentPage,
|
|
||||||
parentDirectory,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function allPageAndDirectoryPaths(wikiEntries: CollectionEntry<"wiki">[]): AllPathInformation {
|
export function relativePagePaths(
|
||||||
const pathInformation: Map<string, CollectionEntry<"wiki"> | null> = new Map();
|
wikiEntries: PageLinkData[],
|
||||||
|
currentPath: string,
|
||||||
|
): Paths {
|
||||||
|
let currentPage: PageLinkData | undefined;
|
||||||
|
let parentDirectory: PageLinkData | undefined | null;
|
||||||
|
const siblingPages: Map<string, PageLinkData> = new Map();
|
||||||
|
const childPages: Map<string, PageLinkData> = new Map();
|
||||||
|
|
||||||
for (const entry of wikiEntries) {
|
const currentPathParsed = parse(currentPath);
|
||||||
pathInformation.set(entry.id, entry);
|
const currentPathExtensionless = join(
|
||||||
|
currentPathParsed.dir,
|
||||||
|
currentPathParsed.name,
|
||||||
|
);
|
||||||
|
|
||||||
let parsedEntryPath = parse(entry.id);
|
const childDirectoryPaths: Set<string> = new Set();
|
||||||
while (parsedEntryPath.dir) {
|
const siblingDirectoryPaths: Set<string> = new Set();
|
||||||
pathInformation.set(parsedEntryPath.dir, null);
|
|
||||||
parsedEntryPath = parse(parsedEntryPath.dir);
|
for (const entry of wikiEntries) {
|
||||||
}
|
const pagePathParsed = parse(entry.id);
|
||||||
|
const pagePathExtensionless = join(pagePathParsed.dir, pagePathParsed.name);
|
||||||
|
|
||||||
|
if (pagePathExtensionless === currentPathExtensionless) {
|
||||||
|
currentPage = entry;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pathInformation;
|
const isInCurrentDirectory = pagePathParsed.dir === currentPathParsed.dir;
|
||||||
}
|
if (isInCurrentDirectory) {
|
||||||
|
siblingPages.set(pagePathExtensionless, entry);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isDirectChild = pagePathParsed.dir === currentPathExtensionless;
|
||||||
|
if (isDirectChild) {
|
||||||
|
childPages.set(pagePathExtensionless, entry);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isIndirectChild = pagePathParsed.dir.startsWith(
|
||||||
|
currentPathExtensionless + sep,
|
||||||
|
);
|
||||||
|
if (isIndirectChild) {
|
||||||
|
const nextPathSeparator = pagePathParsed.dir.indexOf(
|
||||||
|
sep,
|
||||||
|
currentPathExtensionless.length + 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (nextPathSeparator === -1) {
|
||||||
|
childDirectoryPaths.add(pagePathParsed.dir);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
childDirectoryPaths.add(pagePathParsed.dir.slice(0, nextPathSeparator));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isIndirectInCurrentDirectory =
|
||||||
|
currentPathParsed.dir === "" ||
|
||||||
|
pagePathParsed.dir.startsWith(currentPathParsed.dir + sep);
|
||||||
|
if (isIndirectInCurrentDirectory) {
|
||||||
|
const nextPathSeparator = pagePathParsed.dir.indexOf(
|
||||||
|
sep,
|
||||||
|
currentPathParsed.dir.length + 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (nextPathSeparator === -1) {
|
||||||
|
siblingDirectoryPaths.add(pagePathParsed.dir);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
siblingDirectoryPaths.add(pagePathParsed.dir.slice(0, nextPathSeparator));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isParentDirectory = pagePathExtensionless === currentPathParsed.dir;
|
||||||
|
if (isParentDirectory) {
|
||||||
|
parentDirectory = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const childDirectories: PageLinkData[] = [];
|
||||||
|
for (const childDirectoryPath of childDirectoryPaths.values()) {
|
||||||
|
const childDirectoryPage = childPages.get(childDirectoryPath);
|
||||||
|
if (childDirectoryPage) {
|
||||||
|
childDirectories.push(childDirectoryPage);
|
||||||
|
childPages.delete(childDirectoryPath);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const childDirectoryPathParsed = parse(childDirectoryPath);
|
||||||
|
childDirectories.push({
|
||||||
|
id: childDirectoryPath,
|
||||||
|
data: { title: childDirectoryPathParsed.name },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const siblingDirectories: PageLinkData[] = [];
|
||||||
|
for (const siblingDirectoryPath of siblingDirectoryPaths.values()) {
|
||||||
|
const siblingDirectoryPage = siblingPages.get(siblingDirectoryPath);
|
||||||
|
if (siblingDirectoryPage) {
|
||||||
|
siblingDirectories.push(siblingDirectoryPage);
|
||||||
|
siblingPages.delete(siblingDirectoryPath);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const siblingDirectoryPathParsed = parse(siblingDirectoryPath);
|
||||||
|
siblingDirectories.push({
|
||||||
|
id: siblingDirectoryPath,
|
||||||
|
data: { title: siblingDirectoryPathParsed.name },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentPage === undefined) {
|
||||||
|
currentPage = {
|
||||||
|
id: currentPath,
|
||||||
|
data: { title: currentPathParsed.name },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parentDirectory === undefined) {
|
||||||
|
if (currentPathParsed.dir) {
|
||||||
|
const parentDirectoryPathParsed = parse(currentPathParsed.dir);
|
||||||
|
parentDirectory = {
|
||||||
|
id: currentPathParsed.dir,
|
||||||
|
data: { title: parentDirectoryPathParsed.name },
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
parentDirectory = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
siblingPages: Array.from(siblingPages.values()).sort(),
|
||||||
|
childPages: Array.from(childPages.values()).sort(),
|
||||||
|
|
||||||
|
siblingDirectories: siblingDirectories.sort(),
|
||||||
|
childDirectories: childDirectories.sort(),
|
||||||
|
|
||||||
|
currentPage,
|
||||||
|
parentDirectory,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function allPageAndDirectoryPaths(
|
||||||
|
wikiEntries: CollectionEntry<"wiki">[],
|
||||||
|
): AllPathInformation {
|
||||||
|
const pathInformation: Map<string, CollectionEntry<"wiki"> | null> =
|
||||||
|
new Map();
|
||||||
|
|
||||||
|
for (const entry of wikiEntries) {
|
||||||
|
pathInformation.set(entry.id, entry);
|
||||||
|
|
||||||
|
let parsedEntryPath = parse(entry.id);
|
||||||
|
while (parsedEntryPath.dir) {
|
||||||
|
pathInformation.set(parsedEntryPath.dir, null);
|
||||||
|
parsedEntryPath = parse(parsedEntryPath.dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pathInformation;
|
||||||
|
}
|
||||||
|
|
2
src/reset.d.ts
vendored
2
src/reset.d.ts
vendored
|
@ -1 +1 @@
|
||||||
import "@total-typescript/ts-reset";
|
import "@total-typescript/ts-reset";
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
.contents table {
|
.contents table {
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
}
|
}
|
||||||
|
|
||||||
.contents td {
|
.contents td {
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.contents {
|
.contents {
|
||||||
overflow: scroll;
|
overflow: scroll;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
padding: 0em 2em;
|
padding: 0em 2em;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
a:visited {
|
a:visited {
|
||||||
color: blue;
|
color: blue;
|
||||||
}
|
}
|
||||||
|
|
||||||
.contents {
|
.contents {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"extends": "astro/tsconfigs/strictest"
|
"extends": "astro/tsconfigs/strictest"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue