-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 0432da8
Showing
39 changed files
with
6,195 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 4 | ||
max_line_length = 120 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
max_line_length = 80 | ||
|
||
[*.{json,yml,yaml,prettierrc}] | ||
indent_size = 2 |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
* text=auto eol=lf | ||
|
||
*.png binary | ||
*.jpg binary | ||
*.jpeg binary | ||
*.ico binary | ||
*.tff binary | ||
*.woff binary | ||
*.woff2 binary |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Deploy Docs | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
concurrency: | ||
group: pages | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
# Build job | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: npm # or pnpm / yarn | ||
- name: Setup Pages | ||
uses: actions/configure-pages@v4 | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Build with VitePress | ||
run: npm run build:static | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
path: dist | ||
|
||
# Deployment job | ||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
needs: build | ||
runs-on: ubuntu-latest | ||
name: Deploy | ||
steps: | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v4 |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# build output | ||
dist/ | ||
# generated stuff | ||
cache/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
||
# logs | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
|
||
|
||
# environment variables | ||
.env | ||
.env.production | ||
|
||
# macOS-specific files | ||
.DS_Store |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"singleQuote": false, | ||
"semi": false, | ||
"trailingComma": "all", | ||
"quoteProps": "as-needed", | ||
"bracketSpacing": true, | ||
"bracketSameLine": true, | ||
"arrowParens": "always", | ||
"endOfLine": "lf", | ||
"useTabs": false, | ||
"singleAttributePerLine": false | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { z } from "zod"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
const schema = z.object({ | ||
wikis: z.array(z.object({ | ||
name: z.string(), | ||
})), | ||
}) | ||
|
||
const jsonString = fs.readFileSync(path.resolve(__dirname, "../", "wikis.json"), "utf-8"); | ||
const json = schema.parse(JSON.parse(jsonString)) | ||
const wikis: Map<string, WikiEntry> = new Map() | ||
|
||
json.wikis.forEach((wiki) => { | ||
wikis.set(wiki.name, wiki as WikiEntry) | ||
}) | ||
|
||
export interface WikiEntry { | ||
name: string | ||
} | ||
|
||
export class WikiConfig { | ||
constructor(private wikis: Map<string, WikiEntry>) {} | ||
|
||
hasWiki(name: string): boolean { | ||
return this.wikis.has(name) | ||
} | ||
|
||
forEach(onEach: (wiki: WikiEntry) => void) { | ||
this.wikis.forEach(onEach) | ||
} | ||
} | ||
|
||
export default new WikiConfig(wikis) |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import fs from "fs" | ||
import path from "path" | ||
import { execSync } from "child_process" | ||
import WikiConfig, { WikiEntry } from "./WikiConfig" | ||
|
||
const ROOT_DIR = path.resolve(__dirname, "../") | ||
const DIST_DIR = path.join(ROOT_DIR, "dist") | ||
const WIKIS_DIR = path.join(ROOT_DIR, "wikis") | ||
|
||
function run() { | ||
cleanDist() | ||
buildWikis() | ||
} | ||
run() | ||
|
||
function cleanDist() { | ||
console.log("Start cleaning wiki dist directory...") | ||
if (fs.existsSync(DIST_DIR)) { | ||
fs.rmSync(DIST_DIR, { recursive: true }) | ||
} | ||
|
||
fs.mkdirSync(DIST_DIR) | ||
} | ||
|
||
function buildWikis() { | ||
console.log("Start building wikis...") | ||
WikiConfig.forEach((wiki) => { | ||
try { | ||
buildWiki(wiki) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
}) | ||
} | ||
|
||
function buildWiki(wiki: WikiEntry) { | ||
console.log(`Start building ${wiki.name}...`) | ||
const wikiPath = path.join(WIKIS_DIR, wiki.name) | ||
if (!fs.existsSync(wikiPath)) { | ||
throw new Error(`Wiki ${wiki.name} not found`) | ||
} | ||
|
||
runBuild(wiki) | ||
|
||
const wikiDist = path.join(wikiPath, ".vitepress", "dist") | ||
const targetDist = path.join(DIST_DIR, wiki.name) | ||
moveWikiToDist(wikiDist, targetDist) | ||
} | ||
|
||
function runBuild(wiki: WikiEntry) { | ||
execSync(`npm run build wikis/${wiki.name}`, { cwd: ROOT_DIR, stdio: "inherit" }) | ||
} | ||
|
||
function moveWikiToDist(wikiDist: string, targetDist: string) { | ||
if (fs.existsSync(targetDist)) { | ||
fs.rmSync(targetDist, { recursive: true }) | ||
} | ||
|
||
fs.renameSync(wikiDist, targetDist) | ||
|
||
if (fs.existsSync(wikiDist)) { | ||
fs.rmSync(wikiDist, { recursive: true }) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { DefaultTheme, UserConfig } from "vitepress" | ||
|
||
export function defineConfig(config: UserConfig<DefaultTheme.Config>): UserConfig<DefaultTheme.Config> { | ||
config.title = "AlmostWiki" | ||
|
||
if (!config.themeConfig) { | ||
config.themeConfig = {} | ||
} | ||
|
||
config.themeConfig.socialLinks = [ | ||
{ | ||
icon: "github", | ||
link: "https://github.com/AlmostReliable", | ||
}, | ||
{ | ||
icon: "discord", | ||
link: "https://discord.com/invite/ThFnwZCyYY", | ||
}, | ||
] | ||
|
||
config.themeConfig.search = { | ||
provider: "local", | ||
options: { | ||
detailedView: true, | ||
miniSearch: { | ||
searchOptions: { | ||
maxFuzzy: 3, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
config.themeConfig.outline = { | ||
level: [2, 3], | ||
} | ||
|
||
return config | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import fs from "fs" | ||
import express from "express" | ||
import path from "path" | ||
import WikiConfig, { WikiEntry } from "./WikiConfig" | ||
|
||
const DIST_DIR = path.join(__dirname, "../dist") | ||
if(!fs.existsSync(DIST_DIR)) throw new Error("Wiki dist directory not found") | ||
|
||
const app = express() | ||
app.use(express.static(DIST_DIR)) | ||
|
||
app.use((req, res, next) => { | ||
const urlPath = path.posix.normalize(req.path).replace(/^\//, "") | ||
const wikiName = (urlPath.split("/")[0] ?? "").toLowerCase() | ||
|
||
if (!WikiConfig.hasWiki(wikiName)) { | ||
return res.status(404).send("Wiki not found") | ||
} | ||
|
||
next() | ||
}) | ||
|
||
const port = 3000 | ||
app.listen(port, () => { | ||
console.log(`Server running on http://localhost:${port}`) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// https://vitepress.dev/guide/custom-theme | ||
import { h } from "vue" | ||
import { useRoute, useRouter, type Theme } from "vitepress" | ||
import DefaultTheme from "vitepress/theme" | ||
import "./style.css" | ||
|
||
export default { | ||
extends: DefaultTheme, | ||
Layout: () => { | ||
return h(DefaultTheme.Layout, null, { | ||
// https://vitepress.dev/guide/extending-default-theme#layout-slots | ||
}) | ||
}, | ||
enhanceApp({ app, router, siteData }) { | ||
}, | ||
} satisfies Theme |
Oops, something went wrong.