feat: new home page

This commit is contained in:
DIYgod
2024-03-03 17:36:08 +08:00
parent 0b5aca86ea
commit 3bfdf9427c
8 changed files with 182 additions and 179 deletions
+3 -2
View File
@@ -5,7 +5,7 @@ import Sentry from '@sentry/node';
import logger from '@/utils/logger';
import art from 'art-template';
import * as path from 'node:path';
import gitHash from '@/utils/git-hash';
import { gitHash } from '@/utils/git-hash';
import RequestInProgressError from './request-in-progress';
import RejectError from './reject';
@@ -22,8 +22,9 @@ export const errorHandler: ErrorHandler = (error, ctx) => {
const debug = getDebugInfo();
if (ctx.res.headers.get('RSSHub-Cache-Status')) {
debug.hitCache++;
setDebugInfo(debug);
}
debug.error++;
setDebugInfo(debug);
if (config.sentry.dsn) {
Sentry.withScope((scope) => {
-60
View File
@@ -1,60 +0,0 @@
import type { Handler } from 'hono';
import { config } from '@/config';
import art from 'art-template';
import * as path from 'node:path';
import gitHash from '@/utils/git-hash';
import { getDebugInfo } from '@/utils/debug-info';
const startTime = Date.now();
const handler: Handler = (ctx) => {
ctx.header('Cache-Control', 'no-cache');
const debug = getDebugInfo();
const showDebug = !config.debugInfo || config.debugInfo === 'false' ? false : config.debugInfo === 'true' || config.debugInfo === ctx.req.query('debug');
const { disallowRobot, nodeName } = config;
const duration = Date.now() - startTime;
return ctx.html(
art(path.resolve(__dirname, '../views/welcome.art'), {
showDebug,
disallowRobot,
debug: [
nodeName
? {
name: 'Node Name',
value: nodeName,
}
: null,
{
name: 'Git Hash',
value: gitHash,
},
{
name: 'Request Amount',
value: debug.request,
},
{
name: 'Request Frequency',
value: ((debug.request / (duration / 1000)) * 60).toFixed(3) + ' times/minute',
},
{
name: 'Cache Hit Ratio',
value: debug.request ? (debug.hitCache / debug.request).toFixed(3) : 0,
},
{
name: 'ETag Matched',
value: debug.etag,
},
{
name: 'Run Time',
value: (duration / 3_600_000).toFixed(2) + ' hour(s)',
},
],
})
);
};
export default handler;
+10
View File
@@ -0,0 +1,10 @@
import type { Handler } from 'hono';
import Index from '@/views/index';
const handler: Handler = (ctx) => {
ctx.header('Cache-Control', 'no-cache');
return ctx.html(<Index debugQuery={ctx.req.query('debug')} />);
};
export default handler;
+1
View File
@@ -2,6 +2,7 @@ const debug = {
hitCache: 0,
request: 0,
etag: 0,
error: 0,
};
export const getDebugInfo = () => debug;
+5 -3
View File
@@ -1,12 +1,14 @@
import gitRevSync from 'git-rev-sync';
let gitHash = process.env.HEROKU_SLUG_COMMIT?.slice(0, 7) || process.env.VERCEL_GIT_COMMIT_SHA?.slice(0, 7);
let gitHash = process.env.HEROKU_SLUG_COMMIT?.slice(0, 8) || process.env.VERCEL_GIT_COMMIT_SHA?.slice(0, 8);
let gitDate;
if (!gitHash) {
try {
gitHash = gitRevSync.short();
gitHash = gitRevSync.short(undefined, 8);
gitDate = gitRevSync.date();
} catch {
gitHash = 'unknown';
}
}
export default gitHash;
export { gitHash, gitDate };
+163
View File
@@ -0,0 +1,163 @@
import type { FC } from 'hono/jsx';
import { config } from '@/config';
import { gitHash, gitDate } from '@/utils/git-hash';
import { getDebugInfo } from '@/utils/debug-info';
const startTime = Date.now();
const Layout: FC = (props) => (
<html>
<head>
<title>Welcome to RSSHub!</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body className="antialiased text-zinc-700">{props.children}</body>
</html>
);
const Index: FC<{ debugQuery: string | undefined }> = ({ debugQuery }) => {
const debug = getDebugInfo();
const showDebug = !config.debugInfo || config.debugInfo === 'false' ? false : config.debugInfo === 'true' || config.debugInfo === debugQuery;
const { disallowRobot, nodeName } = config;
const duration = Date.now() - startTime;
const info = {
showDebug,
disallowRobot,
debug: [
...(nodeName
? [
{
name: 'Node Name',
value: nodeName,
},
]
: []),
...(gitHash
? [
{
name: 'Git Hash',
value: (
<a className="underline" href={`https://github.com/DIYgod/RSSHub/commit/${gitHash}`}>
{gitHash}
</a>
),
},
]
: []),
...(gitDate
? [
{
name: 'Git Date',
value: gitDate.toUTCString(),
},
]
: []),
{
name: 'Cache Length',
value: config.cache.routeExpire + 's',
},
{
name: 'Request Amount',
value: debug.request,
},
{
name: 'Request Frequency',
value: ((debug.request / (duration / 1000)) * 60).toFixed(3) + ' times/minute',
},
{
name: 'Cache Hit Ratio',
value: debug.request ? ((debug.hitCache / debug.request) * 100).toFixed(2) + '%' : 0,
},
{
name: 'ETag Matched Ratio',
value: debug.request ? ((debug.etag / debug.request) * 100).toFixed(2) + '%' : 0,
},
{
name: 'Health',
value: debug.request ? ((1 - debug.error / debug.request) * 100).toFixed(2) + '%' : 0,
},
{
name: 'Run Time',
value: (duration / 3_600_000).toFixed(2) + ' hour(s)',
},
],
};
return (
<Layout>
<div
className="pointer-events-none absolute w-full h-screen"
style={{
backgroundImage: `url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHZpZXdCb3g9JzAgMCAzMiAzMicgd2lkdGg9JzMyJyBoZWlnaHQ9JzMyJyBmaWxsPSdub25lJyBzdHJva2U9J3JnYigxNSAyMyA0MiAvIDAuMDQpJz48cGF0aCBkPSdNMCAuNUgzMS41VjMyJy8+PC9zdmc+')`,
maskImage: 'linear-gradient(transparent, black, transparent)',
}}
></div>
<div className="w-full h-screen flex items-center justify-center flex-col space-y-4">
<img src="/logo.png" alt="RSSHub" width="100" loading="lazy" />
<h1 className="text-4xl font-bold">
Welcome to <span className="text-[#F5712C]">RSSHub</span>!
</h1>
<p className="text-zinc-500">If you see this page, the RSSHub is successfully installed and working.</p>
<p className="text-xl font-medium text-zinc-600">Everything is RSSible</p>
<div className="font-bold space-x-4 text-sm">
<a target="_blank" href="https://docs.rsshub.app">
<button className="text-white bg-[#F5712C] py-2 px-4 rounded-full">View Docs</button>
</a>
<a target="_blank" href="https://github.com/DIYgod/RSSHub">
<button className="bg-zinc-200 py-2 px-4 rounded-full">View on GitHub</button>
</a>
<a target="_blank" href="https://docs.rsshub.app/support" className="text-[#F5712C]">
<button className="text-white bg-red-500 py-2 px-4 rounded-full">❤️ Sponsor</button>
</a>
</div>
{info.showDebug ? (
<details className="text-xs w-96 !mt-8">
<summary className="text-sm cursor-pointer">Debug Info</summary>
{info.debug.map((item) => (
<div class="debug-item my-3 pl-8">
<span class="debug-key">{item.name}: </span>
<span class="debug-value">{item.value}</span>
</div>
))}
</details>
) : null}
</div>
<div className="absolute bottom-10 text-center w-full text-sm font-medium space-y-2">
<p className="space-x-4">
<a target="_blank" href="https://github.com/DIYgod/RSSHub">
<img className="inline" src="https://icons.ly/github/_/fff" alt="github" width="20" height="20" />
</a>
<a target="_blank" href="https://t.me/rsshub">
<img className="inline" src="https://icons.ly/telegram" alt="telegram group" width="20" height="20" />
</a>
<a target="_blank" href="https://t.me/awesomeRSSHub">
<img className="inline" src="https://icons.ly/telegram" alt="telegram channel" width="20" height="20" />
</a>
<a target="_blank" href="https://twitter.com/_RSSHub" className="text-[#F5712C]">
<img className="inline" src="https://icons.ly/twitter" alt="github" width="20" height="20" />
</a>
</p>
<p className="!mt-6">
Please consider <a target="_blank" href="https://docs.rsshub.app/support" className="text-[#F5712C]">sponsoring</a> to help keep this open source project alive.
</p>
<p>
Made with ❤️ by{' '}
<a target="_blank" href="https://diygod.cc" className="text-[#F5712C]">
DIYgod
</a>{' '}
and{' '}
<a target="_blank" href="https://github.com/DIYgod/RSSHub/graphs/contributors" className="text-[#F5712C]">
Contributors
</a>{' '}
under MIT License.
</p>
</div>
</Layout>
);
};
export default Index;
-114
View File
@@ -1,114 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Welcome to RSSHub!</title>
{{ if disallowRobot }}
<meta name="robots" content="noindex">
{{ /if }}
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-size: 16px;
color: #2c3e50;
}
.content {
position: absolute;
left: 50%;
transform: translate(-50%, 100px);
min-width: 400px;
text-align: center;
}
a {
color: #F5712C;
}
details {
text-align: left;
max-height: 400px;
overflow: auto;
}
details::-webkit-scrollbar {
width: 5px;
}
details::-webkit-scrollbar-thumb {
border-radius: 3px;
background-color: #eee;
}
details::-webkit-scrollbar-thumb:hover {
background-color: #ccc;
}
summary {
margin-bottom: 10px;
outline: none;
cursor: pointer;
}
.debug-key {
width: 120px;
text-align: right;
display: inline-block;
margin-right: 10px;
}
.debug-item {
white-space: nowrap;
margin: 5px 0;
font-size: 12px;
line-height: 24px;
max-width: 75%;
}
.debug-value {
white-space: pre-wrap !important;
overflow-wrap: anywhere;
display: inline-block;
vertical-align: top;
}
</style>
</head>
<body>
<div class="content">
<p>
<img src="/logo.png" alt="RSSHub" width="100" loading="lazy" />
</p>
<h1>Welcome to
<span style="color: #F5712C;">RSSHub</span>!</h1>
<p>If you see this page, the RSSHub is successfully installed and working.</p>
<p>For online documentation and support please refer to
<a href="https://docs.rsshub.app/" target="_blank">docs.rsshub.app</a>.</p>
<p>-- Made with
<i style="color:#d43f57">♥</i> by
<a href="https://diygod.cc" target="_blank">DIYgod</a>
</p>
{{ if showDebug }}
<details>
<summary>debug</summary>
{{ each debug }}
{{ if $value && $value.value }}
<div class="debug-item">
<span class="debug-key">{{ $value.name }}: </span>
<span class="debug-value">{{@ $value.value }}</span>
</div>
{{ /if }}
{{ /each }}
</details>
{{ /if }}
</div>
</body>
</html>
View File