-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PR] Merge pull request #27 from Mak1o/main
[U] Migrate to MDX
- Loading branch information
Showing
14 changed files
with
1,602 additions
and
89 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 |
---|---|---|
@@ -1,47 +1,42 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: Generator | ||
|
||
# Controls when the workflow will run | ||
on: | ||
# Triggers the workflow on push or pull request events but only for the main branch | ||
push: | ||
branches: [ main ] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
# This workflow contains a single job called "build" | ||
build: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
python-version: "3.9" | ||
|
||
- name: "Install dependencies" | ||
run: | | ||
set -xe | ||
python -VV | ||
python -m pip install json5 | ||
- name: "Run generator" | ||
run: "python generator.py" | ||
|
||
- uses: EndBug/add-and-commit@v7 | ||
node-version: 16.x | ||
- name: Cache node_modules | ||
uses: actions/cache@v2 | ||
id: cache | ||
with: | ||
# Determines the way the action fills missing author name and email. Three options are available: | ||
# - github_actor -> UserName <UserName@users.noreply.github.com> | ||
# - user_info -> Your Display Name <your-actual@email.com> | ||
# - github_actions -> github-actions <email associated with the github logo> | ||
# Default: github_actor | ||
default_author: github_actions | ||
path: node_modules | ||
key: ${{ runner.os }}-node-${{ hashFiles('yarn.lock') }} | ||
restore-keys: ${{ runner.os }}-node- | ||
- name: Install Dependencies | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
run: yarn install --production --frozen-lockfile | ||
- name: Build | ||
run: yarn build | ||
- name: Deploy | ||
run: | | ||
git config --global user.name $(git show -s --format='%an' HEAD) | ||
git config --global user.email $(git show -s --format='%ae' HEAD) | ||
# The message for the commit. | ||
# Default: 'Commit from GitHub Actions (name of the workflow)' | ||
message: '[U] Generate json' | ||
cd dist | ||
git init | ||
git add . | ||
git commit -m "Build on $(date '+%Y-%m-%d %H:%M:%S')" | ||
git branch -m gh-pages | ||
git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} | ||
git push -f origin gh-pages |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
{ | ||
"name": "our-data", | ||
"version": "1.0.0", | ||
"description": "Data for https://one-among.us", | ||
"main": "scripts/build.ts", | ||
"repository": "https://github.com/hykilpikonna/our-data", | ||
"author": "Hykilpikonna <me@hydev.org>", | ||
"license": "UNLICENSED", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"build": "node --loader ts-node/esm/transpile-only scripts/build.ts" | ||
}, | ||
"dependencies": { | ||
"@mdx-js/mdx": "^2.1.0", | ||
"@swc/core": "^1.2.159", | ||
"@types/fs-extra": "^9.0.13", | ||
"@types/node": "^16", | ||
"esbuild": "^0.14.27", | ||
"fs-extra": "^10.0.1", | ||
"json5": "^2.2.0", | ||
"ts-node": "^10.7.0", | ||
"typescript": "^4.6.2", | ||
"xdm": "^3.4.0" | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
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,89 @@ | ||
import url from "url"; | ||
import path from "path"; | ||
import fs from "fs-extra"; | ||
|
||
import json5 from "json5"; | ||
|
||
import { renderMdx } from "./mdx.ts"; | ||
|
||
const PUBLIC_DIR = "public"; | ||
|
||
const PEOPLE_DIR = "people"; | ||
const PEOPLE_INFO_FILENAME = "info.json5"; | ||
const PEOPLE_PAGE_FILE = "page.md"; | ||
|
||
const DIST_DIR = "dist"; | ||
const DIST_PEOPLE_LIST = "people-list.json"; | ||
const DIST_PEOPLE_INFO_FILENAME = "info.json"; | ||
const DIST_PEOPLE_PAGE_FILE = "page.js"; | ||
|
||
const projectRoot = path.dirname(path.dirname(url.fileURLToPath(import.meta.url))); | ||
const peopleDir = path.join(projectRoot, PEOPLE_DIR); | ||
const people = fs.readdirSync(peopleDir).map(person => ({ | ||
dirname: person, | ||
srcPath: path.join(peopleDir, person), | ||
distPath: path.join(projectRoot, DIST_DIR, PEOPLE_DIR, person) | ||
})); | ||
|
||
// Transform `info.json5` to `info.json`. | ||
// Extract metadata from `people/${dirname}/info.json5` to `dist/people-list.json`. | ||
function buildPeopleInfoAndList() { | ||
const PEOPLE_LIST_KEYS = ["id", "name", "profileUrl"] as const; | ||
|
||
type PeopleMeta = Record<"path" | typeof PEOPLE_LIST_KEYS[number], unknown>; | ||
const peopleList: PeopleMeta[] = []; | ||
|
||
for (const { dirname, srcPath, distPath } of people) { | ||
const infoFile = fs.readFileSync(path.join(srcPath, PEOPLE_INFO_FILENAME), "utf-8"); | ||
const info = json5.parse(infoFile); | ||
|
||
const peopleMeta = { | ||
path: dirname, | ||
...Object.fromEntries(PEOPLE_LIST_KEYS.map(key => [key, info[key]])) | ||
} as PeopleMeta; | ||
|
||
peopleList.push(peopleMeta); | ||
|
||
fs.ensureDirSync(distPath); | ||
fs.writeFileSync(path.join(distPath, DIST_PEOPLE_INFO_FILENAME), JSON.stringify(info)); | ||
} | ||
|
||
fs.writeFileSync(path.join(projectRoot, DIST_DIR, DIST_PEOPLE_LIST), JSON.stringify(peopleList)); | ||
} | ||
|
||
// Render `people/${dirname}/page.md` to `dist/people/${dirname}/page.js`. | ||
function buildPeoplePages() { | ||
for (const { srcPath, distPath } of people) { | ||
const markdown = fs.readFileSync(path.join(srcPath, PEOPLE_PAGE_FILE), "utf-8"); | ||
const result = renderMdx(markdown); | ||
|
||
fs.ensureDirSync(distPath); | ||
fs.writeFileSync(path.join(distPath, DIST_PEOPLE_PAGE_FILE), result); | ||
} | ||
} | ||
|
||
// Copy `people/${dirname}/comments` and `photos` to `dist/people/${dirname}/`. | ||
function copyPeopleAssets() { | ||
const PEOPLE_ASSETS = ["comments", "photos"]; | ||
|
||
for (const { srcPath, distPath } of people) { | ||
fs.ensureDirSync(distPath); | ||
|
||
for (const assetDirname of PEOPLE_ASSETS) { | ||
const assetSrcPath = path.join(srcPath, assetDirname); | ||
if (fs.pathExistsSync(assetSrcPath)) { | ||
fs.copySync(assetSrcPath, path.join(distPath, assetDirname)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Copy files `public` to dist. | ||
function copyPublic() { | ||
fs.copySync(path.join(projectRoot, PUBLIC_DIR), path.join(projectRoot, DIST_DIR)); | ||
} | ||
|
||
buildPeopleInfoAndList(); | ||
buildPeoplePages(); | ||
copyPeopleAssets(); | ||
copyPublic(); |
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,24 @@ | ||
import * as mdx from "xdm"; | ||
import * as swc from "@swc/core"; | ||
|
||
export function renderMdx(markdown: string): string { | ||
const esmCode = mdx.compileSync(markdown, { | ||
jsxRuntime: "classic", | ||
pragma: "Vue.h", | ||
pragmaFrag: "Vue.Fragment", | ||
pragmaImportSource: "vue" | ||
}).value.toString("utf-8"); | ||
|
||
const codeRemovedImport = esmCode.replace(/^import .*$/m, ""); | ||
|
||
return swc.transformSync(codeRemovedImport, { | ||
jsc: { | ||
parser: { | ||
syntax: "ecmascript" | ||
}, | ||
loose: true, | ||
}, | ||
minify: true, | ||
module: { type: "commonjs" }, | ||
}).code; | ||
} |
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2021", | ||
"lib": [ | ||
"ES2021" | ||
], | ||
"skipLibCheck": true, | ||
"allowSyntheticDefaultImports": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"moduleResolution": "Node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"strict": false, | ||
"module": "ES2020", | ||
"strictBindCallApply": true, | ||
"baseUrl": "./", | ||
"outDir": "./dist" | ||
}, | ||
"include": [ | ||
"scripts" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"dist" | ||
] | ||
} |
Oops, something went wrong.