Skip to content

Commit 3bfdf94

Browse files
committed
feat: new home page
1 parent 0b5aca8 commit 3bfdf94

File tree

8 files changed

+182
-179
lines changed

8 files changed

+182
-179
lines changed

Diff for: lib/errors/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Sentry from '@sentry/node';
55
import logger from '@/utils/logger';
66
import art from 'art-template';
77
import * as path from 'node:path';
8-
import gitHash from '@/utils/git-hash';
8+
import { gitHash } from '@/utils/git-hash';
99

1010
import RequestInProgressError from './request-in-progress';
1111
import RejectError from './reject';
@@ -22,8 +22,9 @@ export const errorHandler: ErrorHandler = (error, ctx) => {
2222
const debug = getDebugInfo();
2323
if (ctx.res.headers.get('RSSHub-Cache-Status')) {
2424
debug.hitCache++;
25-
setDebugInfo(debug);
2625
}
26+
debug.error++;
27+
setDebugInfo(debug);
2728

2829
if (config.sentry.dsn) {
2930
Sentry.withScope((scope) => {

Diff for: lib/routes/index.ts

-60
This file was deleted.

Diff for: lib/routes/index.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Handler } from 'hono';
2+
import Index from '@/views/index';
3+
4+
const handler: Handler = (ctx) => {
5+
ctx.header('Cache-Control', 'no-cache');
6+
7+
return ctx.html(<Index debugQuery={ctx.req.query('debug')} />);
8+
};
9+
10+
export default handler;

Diff for: lib/utils/debug-info.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const debug = {
22
hitCache: 0,
33
request: 0,
44
etag: 0,
5+
error: 0,
56
};
67

78
export const getDebugInfo = () => debug;

Diff for: lib/utils/git-hash.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import gitRevSync from 'git-rev-sync';
22

3-
let gitHash = process.env.HEROKU_SLUG_COMMIT?.slice(0, 7) || process.env.VERCEL_GIT_COMMIT_SHA?.slice(0, 7);
3+
let gitHash = process.env.HEROKU_SLUG_COMMIT?.slice(0, 8) || process.env.VERCEL_GIT_COMMIT_SHA?.slice(0, 8);
4+
let gitDate;
45
if (!gitHash) {
56
try {
6-
gitHash = gitRevSync.short();
7+
gitHash = gitRevSync.short(undefined, 8);
8+
gitDate = gitRevSync.date();
79
} catch {
810
gitHash = 'unknown';
911
}
1012
}
1113

12-
export default gitHash;
14+
export { gitHash, gitDate };

Diff for: lib/views/index.tsx

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
import type { FC } from 'hono/jsx';
2+
3+
import { config } from '@/config';
4+
import { gitHash, gitDate } from '@/utils/git-hash';
5+
import { getDebugInfo } from '@/utils/debug-info';
6+
7+
const startTime = Date.now();
8+
9+
const Layout: FC = (props) => (
10+
<html>
11+
<head>
12+
<title>Welcome to RSSHub!</title>
13+
<script src="https://cdn.tailwindcss.com"></script>
14+
</head>
15+
<body className="antialiased text-zinc-700">{props.children}</body>
16+
</html>
17+
);
18+
19+
const Index: FC<{ debugQuery: string | undefined }> = ({ debugQuery }) => {
20+
const debug = getDebugInfo();
21+
22+
const showDebug = !config.debugInfo || config.debugInfo === 'false' ? false : config.debugInfo === 'true' || config.debugInfo === debugQuery;
23+
const { disallowRobot, nodeName } = config;
24+
25+
const duration = Date.now() - startTime;
26+
27+
const info = {
28+
showDebug,
29+
disallowRobot,
30+
debug: [
31+
...(nodeName
32+
? [
33+
{
34+
name: 'Node Name',
35+
value: nodeName,
36+
},
37+
]
38+
: []),
39+
...(gitHash
40+
? [
41+
{
42+
name: 'Git Hash',
43+
value: (
44+
<a className="underline" href={`https://github.com/DIYgod/RSSHub/commit/${gitHash}`}>
45+
{gitHash}
46+
</a>
47+
),
48+
},
49+
]
50+
: []),
51+
...(gitDate
52+
? [
53+
{
54+
name: 'Git Date',
55+
value: gitDate.toUTCString(),
56+
},
57+
]
58+
: []),
59+
{
60+
name: 'Cache Length',
61+
value: config.cache.routeExpire + 's',
62+
},
63+
{
64+
name: 'Request Amount',
65+
value: debug.request,
66+
},
67+
{
68+
name: 'Request Frequency',
69+
value: ((debug.request / (duration / 1000)) * 60).toFixed(3) + ' times/minute',
70+
},
71+
{
72+
name: 'Cache Hit Ratio',
73+
value: debug.request ? ((debug.hitCache / debug.request) * 100).toFixed(2) + '%' : 0,
74+
},
75+
{
76+
name: 'ETag Matched Ratio',
77+
value: debug.request ? ((debug.etag / debug.request) * 100).toFixed(2) + '%' : 0,
78+
},
79+
{
80+
name: 'Health',
81+
value: debug.request ? ((1 - debug.error / debug.request) * 100).toFixed(2) + '%' : 0,
82+
},
83+
{
84+
name: 'Run Time',
85+
value: (duration / 3_600_000).toFixed(2) + ' hour(s)',
86+
},
87+
],
88+
};
89+
90+
return (
91+
<Layout>
92+
<div
93+
className="pointer-events-none absolute w-full h-screen"
94+
style={{
95+
backgroundImage: `url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHZpZXdCb3g9JzAgMCAzMiAzMicgd2lkdGg9JzMyJyBoZWlnaHQ9JzMyJyBmaWxsPSdub25lJyBzdHJva2U9J3JnYigxNSAyMyA0MiAvIDAuMDQpJz48cGF0aCBkPSdNMCAuNUgzMS41VjMyJy8+PC9zdmc+')`,
96+
maskImage: 'linear-gradient(transparent, black, transparent)',
97+
}}
98+
></div>
99+
<div className="w-full h-screen flex items-center justify-center flex-col space-y-4">
100+
<img src="/logo.png" alt="RSSHub" width="100" loading="lazy" />
101+
<h1 className="text-4xl font-bold">
102+
Welcome to <span className="text-[#F5712C]">RSSHub</span>!
103+
</h1>
104+
<p className="text-zinc-500">If you see this page, the RSSHub is successfully installed and working.</p>
105+
<p className="text-xl font-medium text-zinc-600">Everything is RSSible</p>
106+
<div className="font-bold space-x-4 text-sm">
107+
<a target="_blank" href="https://docs.rsshub.app">
108+
<button className="text-white bg-[#F5712C] py-2 px-4 rounded-full">View Docs</button>
109+
</a>
110+
<a target="_blank" href="https://github.com/DIYgod/RSSHub">
111+
<button className="bg-zinc-200 py-2 px-4 rounded-full">View on GitHub</button>
112+
</a>
113+
<a target="_blank" href="https://docs.rsshub.app/support" className="text-[#F5712C]">
114+
<button className="text-white bg-red-500 py-2 px-4 rounded-full">❤️ Sponsor</button>
115+
</a>
116+
</div>
117+
{info.showDebug ? (
118+
<details className="text-xs w-96 !mt-8">
119+
<summary className="text-sm cursor-pointer">Debug Info</summary>
120+
{info.debug.map((item) => (
121+
<div class="debug-item my-3 pl-8">
122+
<span class="debug-key">{item.name}: </span>
123+
<span class="debug-value">{item.value}</span>
124+
</div>
125+
))}
126+
</details>
127+
) : null}
128+
</div>
129+
<div className="absolute bottom-10 text-center w-full text-sm font-medium space-y-2">
130+
<p className="space-x-4">
131+
<a target="_blank" href="https://github.com/DIYgod/RSSHub">
132+
<img className="inline" src="https://icons.ly/github/_/fff" alt="github" width="20" height="20" />
133+
</a>
134+
<a target="_blank" href="https://t.me/rsshub">
135+
<img className="inline" src="https://icons.ly/telegram" alt="telegram group" width="20" height="20" />
136+
</a>
137+
<a target="_blank" href="https://t.me/awesomeRSSHub">
138+
<img className="inline" src="https://icons.ly/telegram" alt="telegram channel" width="20" height="20" />
139+
</a>
140+
<a target="_blank" href="https://twitter.com/_RSSHub" className="text-[#F5712C]">
141+
<img className="inline" src="https://icons.ly/twitter" alt="github" width="20" height="20" />
142+
</a>
143+
</p>
144+
<p className="!mt-6">
145+
Please consider <a target="_blank" href="https://docs.rsshub.app/support" className="text-[#F5712C]">sponsoring</a> to help keep this open source project alive.
146+
</p>
147+
<p>
148+
Made with ❤️ by{' '}
149+
<a target="_blank" href="https://diygod.cc" className="text-[#F5712C]">
150+
DIYgod
151+
</a>{' '}
152+
and{' '}
153+
<a target="_blank" href="https://github.com/DIYgod/RSSHub/graphs/contributors" className="text-[#F5712C]">
154+
Contributors
155+
</a>{' '}
156+
under MIT License.
157+
</p>
158+
</div>
159+
</Layout>
160+
);
161+
};
162+
163+
export default Index;

Diff for: lib/views/welcome.art

-114
This file was deleted.

Diff for: tailwind.config.js

Whitespace-only changes.

0 commit comments

Comments
 (0)