Skip to content

Commit

Permalink
🐳 chore: 生成 README
Browse files Browse the repository at this point in the history
  • Loading branch information
白云苍狗 committed Nov 18, 2024
1 parent 87676d3 commit 94fbd7a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish-theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
cp ./README_zh-CN.md ./packages/vitepress-theme-async
cp ./README.md ./packages/vitepress-theme-async
node ./scripts/publish.mjs
node ./scripts/sites-check.mjs
yarn config:build
zip -r vitepress-theme-async ./packages/vitepress-theme-async
env:
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,18 @@ If you are using this theme, welcome to leave your site in [Demo Sites | Example
<tr align="center">
<td>
<a href="https://vitepress-theme-async.imalun.com/demosite/" target="_blank">
<img width="80px" src="https://vitepress-theme-async.imalun.com/demosite/img/favicon.svg" />
<img width="80px" src="https://vitepress-theme-async.imalun.com/logo.svg" />
<br />
<sub title="主题默认示例">默认示例</sub>
</a>
</td>
<td>
<a href="https://www.imalun.com" target="_blank">
<img width="80px" src="https://www.imalun.com/images/avatar.jpg" />
<br />
<sub title="醒,亦在人间;梦,亦在人间。">白云苍狗</sub>
</a>
</td>
</tr>
</table>
<!-- demo-end -->
9 changes: 8 additions & 1 deletion README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,18 @@ npm install vitepress-theme-async@latest
<tr align="center">
<td>
<a href="https://vitepress-theme-async.imalun.com/demosite/" target="_blank">
<img width="80px" src="https://vitepress-theme-async.imalun.com/demosite/img/favicon.svg" />
<img width="80px" src="https://vitepress-theme-async.imalun.com/logo.svg" />
<br />
<sub title="主题默认示例">默认示例</sub>
</a>
</td>
<td>
<a href="https://www.imalun.com" target="_blank">
<img width="80px" src="https://www.imalun.com/images/avatar.jpg" />
<br />
<sub title="醒,亦在人间;梦,亦在人间。">白云苍狗</sub>
</a>
</td>
</tr>
</table>
<!-- demo-end -->
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"demo:dev": "vitepress dev demo --host",
"demo:build": "vitepress build demo",
"demo:preview": "vitepress preview demo",
"generate:demo-sites": "node ./scripts/sites-check.mjs",
"lint": "eslint --cache --max-warnings 0 \"**/*.{js,jsx,vue,ts,tsx}\" --fix",
"prettier": "prettier --write \"**/*.{js,jsx,vue,ts,tsx,json,less}\"",
"prepare": "husky install"
Expand Down
44 changes: 44 additions & 0 deletions scripts/sites-check.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import demosite from "../docs/.vitepress/assets/sites.json" assert { type: "json" };
import { readFileSync, writeFileSync } from "fs";
import { resolve as _resolve, dirname } from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const generateDemoSiteHtml = data => {
let str = `<!-- demo-start -->
<table>
<tr align="center">`;
data.forEach((item, index) => {
if (index % 8 === 0 && index > 0) {
str += `
</tr>
<tr align="center">`;
}
str += `
<td>
<a href="${item.url}" target="_blank">
<img width="80px" src="${item.avatar}" />
<br />
<sub title="${item.desc}">${item.name}</sub>
</a>
</td>`;
});
str += `
</tr>
</table>
<!-- demo-end -->`;
return str;
};

const updateReadme = sites => {
const paths = [_resolve(__dirname, "../README.md"), _resolve(__dirname, "../README_zh-CN.md")];
paths.forEach(item => {
let readme = readFileSync(item, "utf-8");
readme = readme.replace(/<!-- demo-start -->(.)+?<!-- demo-end -->/gms, () => generateDemoSiteHtml(sites));
writeFileSync(item, readme, "utf-8");
});
};

updateReadme(demosite);

0 comments on commit 94fbd7a

Please sign in to comment.