Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
LLytho committed Jun 28, 2024
0 parents commit 0432da8
Show file tree
Hide file tree
Showing 39 changed files with 6,195 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
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
9 changes: 9 additions & 0 deletions .gitattributes
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
55 changes: 55 additions & 0 deletions .github/workflows/deploy.yml
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
21 changes: 21 additions & 0 deletions .gitignore
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
12 changes: 12 additions & 0 deletions .prettierrc
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
}
35 changes: 35 additions & 0 deletions main/WikiConfig.ts
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)
64 changes: 64 additions & 0 deletions main/build_wikis.ts
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 })
}
}
38 changes: 38 additions & 0 deletions main/defineAlmostWiki.ts
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
}
26 changes: 26 additions & 0 deletions main/start_dev_server.ts
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}`)
})
16 changes: 16 additions & 0 deletions main/theme/index.ts
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
Loading

0 comments on commit 0432da8

Please sign in to comment.