Skip to content

Commit 688eb44

Browse files
committed
generate entry files for routes
1 parent 3640fea commit 688eb44

File tree

5 files changed

+62
-5
lines changed

5 files changed

+62
-5
lines changed

.github/workflows/deploy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Install dependencies
3939
run: npm ci
4040
- name: Build
41-
run: npm run build && cp ./dist/index.html ./dist/404.html
41+
run: npm run build && node .\generateRoutes.js
4242
- name: Setup Pages
4343
uses: actions/configure-pages@v4
4444
- name: Upload artifact

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55

66
## Notes
77

8-
- Always wrap a page (route) with Layout component
9-
- An internal link must be Link component from 'react-router-dom'
8+
- Always wrap a page (route) with Layout component.
9+
- If you create a new page, add its metadata to routes.json.
10+
- An internal link must be Link component from 'react-router-dom'.

generateRoutes.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import routes from "./routes.json" assert { type: "json" };
2+
import path from "path";
3+
import fs from "fs";
4+
5+
const indexPage = fs.readFileSync("./dist/index.html", "utf-8");
6+
for (const route of routes) {
7+
const routePage = indexPage
8+
.replace(/<title>.+<\/title>/, `<title>${route.title}</title>`)
9+
.replace(
10+
/(<meta.+description.+content=").+("\s*\/>)/g,
11+
`$1${route.description}$2`
12+
);
13+
const filePath = path.join("./dist", route.path + ".html");
14+
const dir = path.dirname(filePath);
15+
if (!fs.existsSync(dir)) {
16+
fs.mkdirSync(dir, { recursive: true });
17+
}
18+
fs.writeFileSync(filePath, routePage, "utf-8");
19+
}

index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/png" href="/ico.png" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>LNReader</title>
8-
<meta name="description" content="Discover and read light novels, novels and more - easier than ever on your Android device.">
7+
<title>Home | LNReader</title>
8+
<meta name="description" content="Discover and read light novels, novels and more - easier than ever on your Android device."/>
99
<meta property="og:title" content="LNReader"/>
1010
<meta property="og:image" content="https://lnreader.github.io/ico.png" />
1111
<meta property="og:description" content="Discover and read light novels, novels and more - easier than ever on your Android device." />

routes.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[
2+
{
3+
"path": "download",
4+
"title": "Download | LNReader",
5+
"description": "Download page that allows users to access and install the latest version of the app."
6+
},
7+
{
8+
"path": "changelogs",
9+
"title": "Changelos | LNReader",
10+
"description": "Changelogs of all LNReader stable releases."
11+
},
12+
{
13+
"path": "contribute",
14+
"title": "Contribute | LNReader",
15+
"description": "Find out how to help build the app."
16+
},
17+
{
18+
"path": "plugins",
19+
"title": "Plugins | LNReader",
20+
"description": "Browse and download sources for LNReader."
21+
},
22+
{
23+
"path": "guides/getting-started",
24+
"title": "Getting started | LNReader",
25+
"description": "Essential information to help you get set up with LNReader."
26+
},
27+
{
28+
"path": "guides/backups",
29+
"title": "Backups | LNReader",
30+
"description": "Backup your novels in remote ways"
31+
},
32+
{
33+
"path": "guides/reader-settings",
34+
"title": "Reader settings | LNReader",
35+
"description": "This section relates to the reading experience in the app and navigating the reader."
36+
}
37+
]

0 commit comments

Comments
 (0)