-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
59 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 |
---|---|---|
@@ -1,58 +1,58 @@ | ||
--- | ||
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
// Directory containing the files | ||
const dir = "src/content/docs/glossary"; | ||
// Read the directory and get an array of filenames | ||
const filenames = fs.readdirSync(dir); | ||
// Map over the filenames and read each file's content and metadata | ||
const files = filenames.map((filename) => { | ||
const filePath = path.join(dir, filename); | ||
const content = fs.readFileSync(filePath, "utf-8"); | ||
const title = path.basename(filename, path.extname(filename)); | ||
return { title, content }; | ||
}); | ||
// Sort the files alphabetically by title | ||
files.sort((a, b) => a.title.localeCompare(b.title)); | ||
// Group the files by the first letter of their title | ||
const sections = files.reduce((acc: { [key: string]: any[] }, file) => { | ||
const firstLetter = file.title.charAt(0).toUpperCase(); | ||
if (!acc[firstLetter]) { | ||
acc[firstLetter] = []; | ||
} | ||
acc[firstLetter].push(file); | ||
return acc; | ||
}, {}); | ||
const headings = Object.entries(sections).map((section: [string, any]) => ({ | ||
depth: 2, | ||
slug: section[0], | ||
text: section[0], | ||
})); | ||
--- | ||
|
||
<StarlightPage frontmatter={{ title: "Glossary" }} headings={headings}> | ||
{ | ||
Object.entries(sections).map((section: [string, any]) => ( | ||
<> | ||
<h2 id={section[0]}>{section[0]}</h2> | ||
<ul> | ||
{section[1].map((file: any) => ( | ||
<li> | ||
<a href={"/starlight-glossary/glossary/" + file.title}> | ||
{file.title} | ||
</a> | ||
</li> | ||
))} | ||
</ul> | ||
</> | ||
)) | ||
} | ||
</StarlightPage> | ||
--- | ||
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
// Directory containing the files | ||
const dir = "src/content/docs/glossary"; | ||
// Read the directory and get an array of filenames | ||
const filenames = fs.readdirSync(dir); | ||
// Map over the filenames and read each file's content and metadata | ||
const files = filenames.map((filename) => { | ||
const filePath = path.join(dir, filename); | ||
const content = fs.readFileSync(filePath, "utf-8"); | ||
const title = path.basename(filename, path.extname(filename)); | ||
return { title, content }; | ||
}); | ||
// Sort the files alphabetically by title | ||
files.sort((a, b) => a.title.localeCompare(b.title)); | ||
// Group the files by the first letter of their title | ||
const sections = files.reduce((acc: { [key: string]: any[] }, file) => { | ||
const firstLetter = file.title.charAt(0).toUpperCase(); | ||
if (!acc[firstLetter]) { | ||
acc[firstLetter] = []; | ||
} | ||
acc[firstLetter].push(file); | ||
return acc; | ||
}, {}); | ||
const headings = Object.entries(sections).map((section: [string, any]) => ({ | ||
depth: 2, | ||
slug: section[0], | ||
text: section[0], | ||
})); | ||
--- | ||
|
||
<StarlightPage frontmatter={{ title: "Glossary" }} headings={headings}> | ||
{ | ||
Object.entries(sections).map((section: [string, any]) => ( | ||
<> | ||
<h2 id={section[0]}>{section[0]}</h2> | ||
<ul> | ||
{section[1].map((file: any) => ( | ||
<li> | ||
<a href={"/qbittorrent-nox-static/glossary/" + file.title}> | ||
{file.title} | ||
</a> | ||
</li> | ||
))} | ||
</ul> | ||
</> | ||
)) | ||
} | ||
</StarlightPage> |