Skip to content

Commit 8e14cd9

Browse files
committed
feat[frontend]: make title configurable
1 parent d6d6a10 commit 8e14cd9

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

frontend/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/png" href="/static/favicon-32x32.png" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Pastebin Worker</title>
7+
<title>%INDEX_PAGE_TITLE%</title>
88
</head>
99
<body>
1010
<div id="root"></div>

frontend/pb.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ export function PasteBin() {
261261

262262
const info = (
263263
<div className="mx-4 lg:mx-0">
264-
<h1 className="text-3xl mt-8 mb-4 relative">Pastebin Worker {toggleDarkModeButton}</h1>
264+
<h1 className="text-3xl mt-8 mb-4 relative">
265+
{INDEX_PAGE_TITLE} {toggleDarkModeButton}
266+
</h1>
265267
<p className="my-2">This is an open source pastebin deployed on Cloudflare Workers. </p>
266268
<p className="my-2">
267269
<b>Usage</b>: paste any text here, submit, then share it with URL. (

frontend/vite-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ declare const API_URL: string
33
declare const REPO: string
44
declare const MAX_EXPIRATION: string
55
declare const DEFAULT_EXPIRATION: string
6+
declare const INDEX_PAGE_TITLE: string

frontend/vite.config.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,28 @@ export default defineConfig(({ mode }) => {
1717
throw new Error(`Cannot find vars.${name} in ${wranglerConfigPath}`)
1818
}
1919
}
20-
let deployUrl = getVar("DEPLOY_URL")
20+
const deployUrl = getVar("DEPLOY_URL")
21+
22+
const indexTitle = getVar("INDEX_PAGE_TITLE") + (mode === "development" ? " (dev)" : "")
23+
const transformHtmlPlugin = () => ({
24+
name: "transform-html",
25+
transformIndexHtml: {
26+
order: "pre",
27+
handler(html) {
28+
return html.replace(/%INDEX_PAGE_TITLE%/g, () => indexTitle)
29+
},
30+
},
31+
})
2132

2233
return {
23-
plugins: [react(), tailwindcss()],
34+
plugins: [react(), tailwindcss(), transformHtmlPlugin()],
2435
define: {
2536
DEPLOY_URL: mode === "development" ? JSON.stringify(devAPIUrl) : JSON.stringify(deployUrl),
2637
API_URL: mode === "development" ? JSON.stringify(devAPIUrl) : JSON.stringify(""),
2738
REPO: JSON.stringify(getVar("REPO")),
2839
MAX_EXPIRATION: JSON.stringify(getVar("MAX_EXPIRATION")),
2940
DEFAULT_EXPIRATION: JSON.stringify(getVar("DEFAULT_EXPIRATION")),
41+
INDEX_PAGE_TITLE: JSON.stringify(indexTitle),
3042
},
3143
server: {
3244
port: 5173,

wrangler.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ REPO = "https://github.com/SharzyL/pastebin-worker"
3737
# the name displayed in TOS
3838
TOS_MAINTAINER = "Sharzy"
3939

40+
# the page title displayed in index page
41+
INDEX_PAGE_TITLE = "Pastebin Worker"
42+
4043
# the email displayed in TOS
4144
TOS_MAIL = "[email protected]"
4245

0 commit comments

Comments
 (0)