Compare commits
25 Commits
65fc12dab6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| cfeee49e68 | |||
| 6d3622555e | |||
| 41641c6f55 | |||
| 6c34c5b564 | |||
| a4850e708f | |||
| 0e917adc3b | |||
| 24fe52cfe3 | |||
| 3595435078 | |||
| c7e51af0e0 | |||
| 26b8061389 | |||
| 81134bfa55 | |||
| 61ec9071e5 | |||
| 1ee413d11b | |||
| ebb570f0e1 | |||
| 21cb0610e1 | |||
| 3867a7f6cc | |||
| ce2185a4c0 | |||
| abe1790ac1 | |||
| be2e6f1ae0 | |||
| 070a63133d | |||
| 7eb0ae75fb | |||
| fef7f239c9 | |||
| 6385b36f6d | |||
| 76247eee92 | |||
| 87f2732028 |
10
.dockerignore
Normal file
10
.dockerignore
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
node_modules/
|
||||||
|
.git/
|
||||||
|
.idea/
|
||||||
|
dist/
|
||||||
|
.astro/
|
||||||
|
.vscode/
|
||||||
|
.claude/
|
||||||
|
*.tar.gz
|
||||||
|
*.log
|
||||||
|
.DS_Store
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
import {defineConfig} from 'astro/config';
|
import {defineConfig} from 'astro/config';
|
||||||
import solidJs from '@astrojs/solid-js';
|
|
||||||
import node from '@astrojs/node';
|
import node from '@astrojs/node';
|
||||||
|
|
||||||
// https://astro.build/config
|
// https://astro.build/config
|
||||||
@@ -10,16 +9,14 @@ export default defineConfig({
|
|||||||
server: {
|
server: {
|
||||||
host: "0.0.0.0",
|
host: "0.0.0.0",
|
||||||
},
|
},
|
||||||
integrations: [solidJs()],
|
|
||||||
adapter: node({
|
adapter: node({
|
||||||
mode: 'standalone'
|
mode: 'standalone'
|
||||||
}),
|
}),
|
||||||
vite: {
|
vite: {
|
||||||
plugins: [],
|
|
||||||
server: {
|
server: {
|
||||||
watch: {
|
...(process.argv.includes('dev')
|
||||||
usePolling: true,
|
? {watch: {usePolling: true}}
|
||||||
},
|
: {}),
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,17 +11,14 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@astrojs/node": "11.0.2",
|
"@astrojs/node": "11.0.2",
|
||||||
"@astrojs/solid-js": "^5.1.3",
|
|
||||||
"astro": "^7.0.6",
|
"astro": "^7.0.6",
|
||||||
"clipboard": "^2.0.11",
|
"clipboard": "^2.0.11",
|
||||||
"dayjs": "^1.11.21",
|
"dayjs": "^1.11.21",
|
||||||
"github-markdown-css": "^5.9.0",
|
|
||||||
"jsdom": "^29.1.1",
|
"jsdom": "^29.1.1",
|
||||||
"ky": "^2.0.2",
|
"ky": "^2.0.2",
|
||||||
"modern-normalize": "^3.0.1",
|
"modern-normalize": "^3.0.1",
|
||||||
"photoswipe": "^5.4.4",
|
"photoswipe": "^5.4.4",
|
||||||
"shiki": "^4.3.1",
|
"shiki": "^4.3.1"
|
||||||
"solid-js": "^1.9.14"
|
|
||||||
},
|
},
|
||||||
"volta": {
|
"volta": {
|
||||||
"node": "22.21.1"
|
"node": "22.21.1"
|
||||||
|
|||||||
1091
pnpm-lock.yaml
generated
1091
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,13 @@
|
|||||||
FROM alpine:3.22 AS base
|
FROM alpine:3.22 AS base
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apk add --no-cache --update nodejs pnpm
|
RUN apk add --no-cache --update nodejs
|
||||||
|
|
||||||
FROM base AS install
|
FROM base AS install
|
||||||
|
RUN apk add --no-cache pnpm
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
COPY package.json pnpm-lock.yaml ./
|
COPY package.json pnpm-lock.yaml ./
|
||||||
RUN pnpm install
|
RUN pnpm install --frozen-lockfile
|
||||||
|
|
||||||
FROM install AS build
|
FROM install AS build
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|||||||
275
src/components/ContributionHeatmap.astro
Normal file
275
src/components/ContributionHeatmap.astro
Normal file
@@ -0,0 +1,275 @@
|
|||||||
|
---
|
||||||
|
import {dayjs} from "@/lib/format.ts";
|
||||||
|
import type {HeatmapPoint} from "@/types/stats.ts";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
points?: HeatmapPoint[]
|
||||||
|
/** IANA 时区,用于把时间戳归到某一天 */
|
||||||
|
timeZone?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const {points = [], timeZone = "Asia/Shanghai"} = Astro.props;
|
||||||
|
|
||||||
|
const CELL = 11;
|
||||||
|
const GAP = 3;
|
||||||
|
const STEP = CELL + GAP;
|
||||||
|
const TOP = 20;
|
||||||
|
const LEFT = 26;
|
||||||
|
|
||||||
|
type GridCell = {
|
||||||
|
key: string
|
||||||
|
x: number
|
||||||
|
y: number
|
||||||
|
value: number
|
||||||
|
level: number
|
||||||
|
}
|
||||||
|
|
||||||
|
const toDateText = (key: string) => key.replaceAll("-", ".");
|
||||||
|
|
||||||
|
// 按天聚合:接口按分钟返回,同一天可能有多条
|
||||||
|
const byDay = new Map<string, number>();
|
||||||
|
for (const {timestamp, contributions} of points) {
|
||||||
|
if (!Number.isFinite(timestamp) || !Number.isFinite(contributions)) continue;
|
||||||
|
const key = dayjs(timestamp * 1000).tz(timeZone).format("YYYY-MM-DD");
|
||||||
|
byDay.set(key, (byDay.get(key) ?? 0) + Math.max(0, contributions));
|
||||||
|
}
|
||||||
|
|
||||||
|
const days = [...byDay.keys()].sort();
|
||||||
|
|
||||||
|
const cells: GridCell[] = [];
|
||||||
|
const monthLabels: {x: number, label: string}[] = [];
|
||||||
|
const weekdayLabels = [
|
||||||
|
{row: 0, label: "一"},
|
||||||
|
{row: 2, label: "三"},
|
||||||
|
{row: 4, label: "五"}
|
||||||
|
];
|
||||||
|
|
||||||
|
let weeks = 0;
|
||||||
|
let total = 0;
|
||||||
|
let firstDate = "";
|
||||||
|
let lastDate = "";
|
||||||
|
|
||||||
|
const firstKey = days.at(0);
|
||||||
|
|
||||||
|
if (firstKey) {
|
||||||
|
const first = dayjs.tz(firstKey, timeZone).startOf("day");
|
||||||
|
const today = dayjs().tz(timeZone).startOf("day");
|
||||||
|
const lastData = dayjs.tz(days.at(-1) ?? firstKey, timeZone).startOf("day");
|
||||||
|
// 末尾补到今天,保证最后一列是完整的自然周
|
||||||
|
const endDay = lastData.isAfter(today) ? lastData : today;
|
||||||
|
// 列从周一开始、到周日结束
|
||||||
|
const start = first.subtract((first.day() + 6) % 7, "day");
|
||||||
|
const end = endDay.add(6 - ((endDay.day() + 6) % 7), "day");
|
||||||
|
|
||||||
|
total = [...byDay.values()].reduce((sum, value) => sum + value, 0);
|
||||||
|
firstDate = firstKey;
|
||||||
|
lastDate = endDay.format("YYYY-MM-DD");
|
||||||
|
|
||||||
|
// 用非零数据的分位数划分 4 档,避免个别高峰压扁其余格子
|
||||||
|
const nonZero = [...byDay.values()].filter((value) => value > 0).sort((a, b) => a - b);
|
||||||
|
const quantile = (p: number) => nonZero[Math.min(nonZero.length - 1, Math.floor(p * (nonZero.length - 1)))];
|
||||||
|
const t1 = Math.max(1, quantile(0.4) ?? 1);
|
||||||
|
const t2 = Math.max(t1 + 1, quantile(0.7) ?? 2);
|
||||||
|
const t3 = Math.max(t2 + 1, quantile(0.9) ?? 3);
|
||||||
|
const levelOf = (value: number) =>
|
||||||
|
value <= 0 ? 0 : value <= t1 ? 1 : value <= t2 ? 2 : value <= t3 ? 3 : 4;
|
||||||
|
|
||||||
|
let week = 0;
|
||||||
|
let weekday = 0;
|
||||||
|
for (let cursor = start; !cursor.isAfter(end); cursor = cursor.add(1, "day")) {
|
||||||
|
const key = cursor.format("YYYY-MM-DD");
|
||||||
|
const value = byDay.get(key) ?? 0;
|
||||||
|
|
||||||
|
cells.push({
|
||||||
|
key,
|
||||||
|
x: LEFT + week * STEP,
|
||||||
|
y: TOP + weekday * STEP,
|
||||||
|
value,
|
||||||
|
level: levelOf(value)
|
||||||
|
});
|
||||||
|
|
||||||
|
weekday += 1;
|
||||||
|
if (weekday === 7) {
|
||||||
|
weekday = 0;
|
||||||
|
week += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
weeks = week + (weekday > 0 ? 1 : 0);
|
||||||
|
|
||||||
|
// 每月第一次出现的列打上月份标签
|
||||||
|
let lastMonth = 0;
|
||||||
|
for (let i = 0; i < weeks; i++) {
|
||||||
|
const month = start.add(i, "week").month() + 1;
|
||||||
|
if (month !== lastMonth) {
|
||||||
|
monthLabels.push({x: LEFT + i * STEP, label: `${month}月`});
|
||||||
|
lastMonth = month;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const width = weeks > 0 ? LEFT + (weeks - 1) * STEP + CELL + 2 : 0;
|
||||||
|
const height = TOP + 7 * STEP - GAP + 2;
|
||||||
|
const levels = [0, 1, 2, 3, 4];
|
||||||
|
---
|
||||||
|
|
||||||
|
{
|
||||||
|
firstKey ? (
|
||||||
|
<section class="heatmap">
|
||||||
|
<div class="heatmap__head">
|
||||||
|
<span class="heatmap__range">{toDateText(firstDate)} - {toDateText(lastDate)}</span>
|
||||||
|
<span class="heatmap__total">共 <strong>{total}</strong> 次贡献</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="heatmap__scroll" data-heatmap-scroll>
|
||||||
|
<svg
|
||||||
|
width={width}
|
||||||
|
height={height}
|
||||||
|
viewBox={`0 0 ${width} ${height}`}
|
||||||
|
role="img"
|
||||||
|
aria-label={`代码贡献热力图,${toDateText(firstDate)} 至 ${toDateText(lastDate)},共 ${total} 次贡献`}
|
||||||
|
>
|
||||||
|
{monthLabels.map(({x, label}) => (
|
||||||
|
<text class="heatmap__month" x={x} y={10}>{label}</text>
|
||||||
|
))}
|
||||||
|
{weekdayLabels.map(({row, label}) => (
|
||||||
|
<text class="heatmap__weekday" x={0} y={TOP + row * STEP + CELL - 2}>{label}</text>
|
||||||
|
))}
|
||||||
|
{cells.map((cell) => (
|
||||||
|
<rect
|
||||||
|
class={`heatmap__cell heatmap__cell--${cell.level}`}
|
||||||
|
x={cell.x}
|
||||||
|
y={cell.y}
|
||||||
|
width={CELL}
|
||||||
|
height={CELL}
|
||||||
|
rx={2.5}
|
||||||
|
>
|
||||||
|
<title>{cell.key} · {cell.value > 0 ? `${cell.value} 次贡献` : "无贡献"}</title>
|
||||||
|
</rect>
|
||||||
|
))}
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="heatmap__foot">
|
||||||
|
<div class="heatmap__legend" aria-hidden="true">
|
||||||
|
<span>少</span>
|
||||||
|
{levels.map((level) => <span class={`heatmap__legend-cell heatmap__cell--${level}`}></span>)}
|
||||||
|
<span>多</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
) : (
|
||||||
|
<p class="heatmap__empty">暂无贡献数据</p>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.heatmap {
|
||||||
|
padding: 14px 20px 16px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-secondary, #6b7280);
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap__head {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 12px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap__range {
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
letter-spacing: 0.2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap__total strong {
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-color, #2b2f36);
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap__scroll {
|
||||||
|
overflow-x: auto;
|
||||||
|
overflow-y: hidden;
|
||||||
|
padding-bottom: 4px;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap__scroll svg {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap__cell {
|
||||||
|
fill: var(--hm-color, #eceff4);
|
||||||
|
shape-rendering: geometricPrecision;
|
||||||
|
transition: fill 0.12s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap__cell:hover {
|
||||||
|
stroke: var(--text-color, #2b2f36);
|
||||||
|
stroke-width: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GitHub 贡献图浅色主题配色 */
|
||||||
|
.heatmap__cell--0 { --hm-color: #ebedf0; }
|
||||||
|
.heatmap__cell--1 { --hm-color: #9be9a8; }
|
||||||
|
.heatmap__cell--2 { --hm-color: #40c463; }
|
||||||
|
.heatmap__cell--3 { --hm-color: #30a14e; }
|
||||||
|
.heatmap__cell--4 { --hm-color: #216e39; }
|
||||||
|
|
||||||
|
.heatmap__month,
|
||||||
|
.heatmap__weekday {
|
||||||
|
fill: var(--text-secondary, #6b7280);
|
||||||
|
font-size: 10px;
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap__weekday {
|
||||||
|
text-anchor: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap__foot {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap__legend {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap__legend-cell {
|
||||||
|
display: inline-block;
|
||||||
|
width: 11px;
|
||||||
|
height: 11px;
|
||||||
|
border-radius: 2.5px;
|
||||||
|
background: var(--hm-color, #eceff4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.heatmap__empty {
|
||||||
|
margin: 0;
|
||||||
|
padding: 24px 20px;
|
||||||
|
font-size: 13px;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--text-secondary, #6b7280);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
.heatmap {
|
||||||
|
padding: 12px 14px 14px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// 数据从最早一天排到最新一天,窄屏下默认展示最近的部分
|
||||||
|
document.querySelectorAll<HTMLElement>("[data-heatmap-scroll]").forEach((scroller) => {
|
||||||
|
if (scroller.scrollWidth > scroller.clientWidth) {
|
||||||
|
scroller.scrollLeft = scroller.scrollWidth;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -28,14 +28,14 @@ const {posts} = Astro.props
|
|||||||
align-items: baseline;
|
align-items: baseline;
|
||||||
gap: 20px;
|
gap: 20px;
|
||||||
padding: 26px 0;
|
padding: 26px 0;
|
||||||
border-bottom: 1px solid #e8e8e8;
|
border-bottom: var(--border-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.post .d {
|
.post .d {
|
||||||
font-size: 12px;
|
font-size: 14px;
|
||||||
color: #b8b8b8;
|
color: var(--text-meta);
|
||||||
min-width: 80px;
|
min-width: 80px;
|
||||||
letter-spacing: 0.1em;
|
letter-spacing: 1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post h2 {
|
.post h2 {
|
||||||
@@ -48,12 +48,15 @@ const {posts} = Astro.props
|
|||||||
}
|
}
|
||||||
|
|
||||||
.post h2 a {
|
.post h2 a {
|
||||||
color: #181818;
|
color: var(--text-primary);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post h2 a:hover {
|
.post h2 a:hover {
|
||||||
color: #334155;
|
color: var(--text-title-hover);
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
text-underline-offset: 6px;
|
text-underline-offset: 6px;
|
||||||
}
|
}
|
||||||
@@ -74,7 +77,7 @@ const {posts} = Astro.props
|
|||||||
}
|
}
|
||||||
|
|
||||||
.post h2 {
|
.post h2 {
|
||||||
font-size: 14px;
|
font-size: 15px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
176
src/components/Post/Toc.astro
Normal file
176
src/components/Post/Toc.astro
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
---
|
||||||
|
import { type TocNode } from "@/lib/processHtml";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
toc: TocNode[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const { toc } = Astro.props;
|
||||||
|
const lowLevel = Math.min(...toc.map((v) => v.level));
|
||||||
|
---
|
||||||
|
|
||||||
|
<div class="toc-mount">
|
||||||
|
<div class="toc">
|
||||||
|
{
|
||||||
|
toc.map((item) => {
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
href={`#${item.id}`}
|
||||||
|
class="toc-item"
|
||||||
|
style={{ paddingLeft: `${(item.level - lowLevel) * 8}px` }}
|
||||||
|
>
|
||||||
|
{item.text}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.toc-mount {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: -64px;
|
||||||
|
right: -320px;
|
||||||
|
width: 280px;
|
||||||
|
padding: 0px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc {
|
||||||
|
position: sticky;
|
||||||
|
top: 60px;
|
||||||
|
height: calc(100vh - 120px);
|
||||||
|
width: 100%;
|
||||||
|
overflow-y: auto;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
border-left: var(--border-secondary);
|
||||||
|
padding-left: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-item {
|
||||||
|
color: var(--text-primary);
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-item:hover {
|
||||||
|
color: var(--text-title-hover);
|
||||||
|
text-shadow:
|
||||||
|
0.3px 0 0 currentColor,
|
||||||
|
-0.3px 0 0 currentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-item.is-active {
|
||||||
|
position: relative;
|
||||||
|
color: var(--text-title-hover);
|
||||||
|
text-shadow:
|
||||||
|
0.3px 0 0 currentColor,
|
||||||
|
-0.3px 0 0 currentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-item.is-active::before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
left: -25px;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
width: 2px;
|
||||||
|
height: 18px;
|
||||||
|
border-radius: 2px;
|
||||||
|
background: currentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1250px) {
|
||||||
|
.toc-mount {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const links = Array.from(
|
||||||
|
document.querySelectorAll<HTMLAnchorElement>(".toc-item"),
|
||||||
|
);
|
||||||
|
|
||||||
|
const headings = links
|
||||||
|
.map((link) => {
|
||||||
|
const id = link.getAttribute("href")?.slice(1);
|
||||||
|
return id ? { link, heading: document.getElementById(id) } : null;
|
||||||
|
})
|
||||||
|
.filter((x): x is { link: HTMLAnchorElement; heading: HTMLElement } =>
|
||||||
|
Boolean(x?.heading),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (headings.length > 0) {
|
||||||
|
const toc = document.querySelector<HTMLElement>(".toc");
|
||||||
|
const ACTIVE_OFFSET = 100;
|
||||||
|
|
||||||
|
let currentId: string | null = null;
|
||||||
|
let raf = 0;
|
||||||
|
|
||||||
|
const scrollActiveIntoView = (link: HTMLAnchorElement) => {
|
||||||
|
if (!toc) return;
|
||||||
|
const containerTop = toc.getBoundingClientRect().top;
|
||||||
|
const linkTop =
|
||||||
|
link.getBoundingClientRect().top - containerTop + toc.scrollTop;
|
||||||
|
const linkBottom =
|
||||||
|
link.getBoundingClientRect().bottom - containerTop + toc.scrollTop;
|
||||||
|
if (linkTop < toc.scrollTop) {
|
||||||
|
toc.scrollTop = linkTop;
|
||||||
|
} else if (linkBottom > toc.scrollTop + toc.clientHeight) {
|
||||||
|
toc.scrollTop = linkBottom - toc.clientHeight;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const setActive = (id: string | null) => {
|
||||||
|
if (id === currentId) return;
|
||||||
|
currentId = id;
|
||||||
|
for (const { link, heading } of headings) {
|
||||||
|
const active = heading.id === id;
|
||||||
|
link.classList.toggle("is-active", active);
|
||||||
|
if (active) {
|
||||||
|
link.setAttribute("aria-current", "location");
|
||||||
|
scrollActiveIntoView(link);
|
||||||
|
} else {
|
||||||
|
link.removeAttribute("aria-current");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const update = () => {
|
||||||
|
raf = 0;
|
||||||
|
|
||||||
|
const doc = document.documentElement;
|
||||||
|
const atBottom =
|
||||||
|
window.scrollY + window.innerHeight >= doc.scrollHeight - 4;
|
||||||
|
|
||||||
|
let activeId: string | null = null;
|
||||||
|
|
||||||
|
if (atBottom) {
|
||||||
|
activeId = headings[headings.length - 1].heading.id;
|
||||||
|
} else {
|
||||||
|
for (const { heading } of headings) {
|
||||||
|
if (heading.getBoundingClientRect().top <= ACTIVE_OFFSET) {
|
||||||
|
activeId = heading.id;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setActive(activeId);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onScroll = () => {
|
||||||
|
if (raf) return;
|
||||||
|
raf = requestAnimationFrame(update);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("scroll", onScroll, { passive: true });
|
||||||
|
window.addEventListener("resize", onScroll, { passive: true });
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
76
src/components/ThemeIcon.astro
Normal file
76
src/components/ThemeIcon.astro
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
---
|
||||||
|
---
|
||||||
|
<div class="theme-toggle" id="themeToggle" aria-label="Toggle theme">
|
||||||
|
<svg aria-hidden="true" width="16px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||||
|
<path class="sun" fill-rule="evenodd"
|
||||||
|
d="M12 17.5a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zm0 1.5a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm12-7a.8.8 0 0 1-.8.8h-2.4a.8.8 0 0 1 0-1.6h2.4a.8.8 0 0 1 .8.8zM4 12a.8.8 0 0 1-.8.8H.8a.8.8 0 0 1 0-1.6h2.5a.8.8 0 0 1 .8.8zm16.5-8.5a.8.8 0 0 1 0 1l-1.8 1.8a.8.8 0 0 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM6.3 17.7a.8.8 0 0 1 0 1l-1.7 1.8a.8.8 0 1 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM12 0a.8.8 0 0 1 .8.8v2.5a.8.8 0 0 1-1.6 0V.8A.8.8 0 0 1 12 0zm0 20a.8.8 0 0 1 .8.8v2.4a.8.8 0 0 1-1.6 0v-2.4a.8.8 0 0 1 .8-.8zM3.5 3.5a.8.8 0 0 1 1 0l1.8 1.8a.8.8 0 1 1-1 1L3.5 4.6a.8.8 0 0 1 0-1zm14.2 14.2a.8.8 0 0 1 1 0l1.8 1.7a.8.8 0 0 1-1 1l-1.8-1.7a.8.8 0 0 1 0-1z"/>
|
||||||
|
<path class="moon" fill-rule="evenodd"
|
||||||
|
d="M16.5 6A10.5 10.5 0 0 1 4.7 16.4 8.5 8.5 0 1 0 16.4 4.7l.1 1.3zm-1.7-2a9 9 0 0 1 .2 2 9 9 0 0 1-11 8.8 9.4 9.4 0 0 1-.8-.3c-.4 0-.8.3-.7.7a10 10 0 0 0 .3.8 10 10 0 0 0 9.2 6 10 10 0 0 0 4-19.2 9.7 9.7 0 0 0-.9-.3c-.3-.1-.7.3-.6.7a9 9 0 0 1 .3.8z"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#themeToggle {
|
||||||
|
border: 0;
|
||||||
|
background: none;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-toggle {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sun {
|
||||||
|
fill: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.moon {
|
||||||
|
fill: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.dark) .sun {
|
||||||
|
fill: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.dark) .moon {
|
||||||
|
fill: white;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script is:inline>
|
||||||
|
const meta = document.querySelector('meta[name="theme-color"]');
|
||||||
|
|
||||||
|
const theme = (() => {
|
||||||
|
const localStorageTheme = localStorage?.getItem("theme") ?? '';
|
||||||
|
if (['dark', 'light'].includes(localStorageTheme)) {
|
||||||
|
return localStorageTheme;
|
||||||
|
}
|
||||||
|
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||||
|
return 'dark';
|
||||||
|
}
|
||||||
|
return 'light';
|
||||||
|
})();
|
||||||
|
|
||||||
|
if (theme === 'light') {
|
||||||
|
document.documentElement.classList.remove('dark');
|
||||||
|
meta.setAttribute('content', '#ffffff');
|
||||||
|
} else {
|
||||||
|
document.documentElement.classList.add('dark');
|
||||||
|
meta.setAttribute('content', '#0a0a0a');
|
||||||
|
}
|
||||||
|
|
||||||
|
window.localStorage.setItem('theme', theme);
|
||||||
|
|
||||||
|
const handleToggleClick = () => {
|
||||||
|
const element = document.documentElement;
|
||||||
|
element.classList.toggle("dark");
|
||||||
|
|
||||||
|
const isDark = element.classList.contains("dark");
|
||||||
|
meta.setAttribute('content', isDark ? '#0a0a0a' : '#ffffff');
|
||||||
|
localStorage.setItem("theme", isDark ? "dark" : "light");
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("themeToggle")?.addEventListener("click", handleToggleClick);
|
||||||
|
</script>
|
||||||
@@ -2,6 +2,6 @@ export const siteConfig = {
|
|||||||
site: "https://ua42.com",
|
site: "https://ua42.com",
|
||||||
siteTitle: "Uroboros",
|
siteTitle: "Uroboros",
|
||||||
postPageSize: 7,
|
postPageSize: 7,
|
||||||
description: "一个人的自留地 ,不欢迎我,也不欢迎你。",
|
description: "love yourself.",
|
||||||
git: "https://git.ua42.com"
|
git: "https://git.ua42.com"
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/layouts/BaseLayout.astro
Normal file
33
src/layouts/BaseLayout.astro
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
---
|
||||||
|
import "@/styles/global.css";
|
||||||
|
import { siteConfig } from "@/consts.ts";
|
||||||
|
|
||||||
|
const { siteTitle } = siteConfig;
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
title?: string;
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { title, description } = Astro.props;
|
||||||
|
const pageTitle = title ? `${title} - ${siteTitle}` : siteTitle;
|
||||||
|
---
|
||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta
|
||||||
|
name="viewport"
|
||||||
|
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
|
||||||
|
/>
|
||||||
|
<link rel="icon" href="/favicon.ico" />
|
||||||
|
<meta name="generator" content={Astro.generator} />
|
||||||
|
<meta name="description" content={description} />
|
||||||
|
<meta name="theme-color" content="#ffffff" />
|
||||||
|
<title>{pageTitle}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<slot />
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,54 +1,23 @@
|
|||||||
---
|
---
|
||||||
import "@/styles/global.css";
|
import BaseLayout from "./BaseLayout.astro";
|
||||||
import {siteConfig} from "@/consts.ts";
|
|
||||||
import PageHeader from "./PageHeader.astro";
|
import PageHeader from "./PageHeader.astro";
|
||||||
import PageFooter from "./PageFooter.astro";
|
import PageFooter from "./PageFooter.astro";
|
||||||
|
|
||||||
const {siteTitle} = siteConfig;
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
title?: string;
|
|
||||||
description?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const {title, description} = Astro.props;
|
|
||||||
const pageTitle = title ? `${title} - ${siteTitle}` : siteTitle;
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<!doctype html>
|
<BaseLayout {...Astro.props}>
|
||||||
<html lang="zh-CN">
|
<div class="container">
|
||||||
<head>
|
<PageHeader />
|
||||||
<meta charset="UTF-8"/>
|
|
||||||
<meta
|
|
||||||
name="viewport"
|
|
||||||
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
|
|
||||||
/>
|
|
||||||
<link rel="icon" type="image/svg+xml" href="/favicon.ico"/>
|
|
||||||
<meta name="generator" content={Astro.generator}/>
|
|
||||||
<meta name="description" content={description}/>
|
|
||||||
<meta name="theme-color" content="#ffffff"/>
|
|
||||||
<title>{pageTitle}</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<PageHeader/>
|
|
||||||
<main>
|
<main>
|
||||||
<slot></slot>
|
<slot />
|
||||||
</main>
|
</main>
|
||||||
<PageFooter />
|
<PageFooter />
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</BaseLayout>
|
||||||
</html>
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
|
||||||
background: #ffffff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: var(--layout-width);
|
max-width: var(--layout-width);
|
||||||
height: 100%;
|
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 24px;
|
padding: 24px;
|
||||||
@@ -59,11 +28,17 @@ const pageTitle = title ? `${title} - ${siteTitle}` : siteTitle;
|
|||||||
main {
|
main {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding: 24px 0;
|
padding: 24px 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 640px) {
|
@media (max-width: 640px) {
|
||||||
.container {
|
.container {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main{
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,26 +1,23 @@
|
|||||||
<footer>
|
<footer>
|
||||||
<div>© 2026 Uroboros</div>
|
<div>© 2026 Uroboros</div>
|
||||||
<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">备案号:鄂ICP备2023000060号-2</a>
|
<a href="https://beian.miit.gov.cn" target="_blank"
|
||||||
|
>备案号:鄂ICP备2023000060号-2</a
|
||||||
|
>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
footer {
|
footer {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
height: 84px;
|
height: 64px;
|
||||||
padding-bottom: 24px;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
color: var(--text-tertiary);
|
color: var(--text-secondary);
|
||||||
}
|
max-width: var(--layout-width);
|
||||||
|
margin: 0 auto;
|
||||||
@media (max-width: 640px) {
|
width: 100%;
|
||||||
footer {
|
|
||||||
height: 64px;
|
|
||||||
padding-bottom: 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
---
|
---
|
||||||
import {siteConfig} from "@/consts.ts";
|
import { siteConfig } from "@/consts.ts";
|
||||||
const {siteTitle,git} = siteConfig;
|
import ThemeIcon from "@/components/ThemeIcon.astro";
|
||||||
|
|
||||||
|
const { siteTitle, git } = siteConfig;
|
||||||
---
|
---
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
@@ -8,6 +10,8 @@ const {siteTitle,git} = siteConfig;
|
|||||||
<nav>
|
<nav>
|
||||||
<a href="/archive">归档</a>
|
<a href="/archive">归档</a>
|
||||||
<a target="_blank" href={git}>git</a>
|
<a target="_blank" href={git}>git</a>
|
||||||
|
|
||||||
|
<ThemeIcon />
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
@@ -17,13 +21,16 @@ const {siteTitle,git} = siteConfig;
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
border-bottom: var(--border-primary);
|
border-bottom: var(--border-primary);
|
||||||
margin-top: 32px;
|
width: 100%;
|
||||||
padding-bottom: 24px;
|
max-width: var(--layout-width);
|
||||||
|
padding: 32px 0 24px;
|
||||||
|
margin: 0 auto 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
nav {
|
nav {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 12px;
|
align-items: center;
|
||||||
|
gap: 16px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
}
|
}
|
||||||
@@ -39,7 +46,7 @@ const {siteTitle,git} = siteConfig;
|
|||||||
|
|
||||||
@media (max-width: 640px) {
|
@media (max-width: 640px) {
|
||||||
header {
|
header {
|
||||||
margin-top: 12px;
|
padding-top: 12px;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import timezone from 'dayjs/plugin/timezone';
|
|||||||
dayjs.extend(utc);
|
dayjs.extend(utc);
|
||||||
dayjs.extend(timezone);
|
dayjs.extend(timezone);
|
||||||
|
|
||||||
|
export { dayjs };
|
||||||
|
|
||||||
export const formatDatetime = (date: string,format = 'YYYY-MM-DD HH:mm') => {
|
export const formatDatetime = (date: string,format = 'YYYY-MM-DD HH:mm') => {
|
||||||
return dayjs(date).tz('Asia/Shanghai').format(format);
|
return dayjs(date).tz('Asia/Shanghai').format(format);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
import {JSDOM} from 'jsdom'
|
import {JSDOM} from "jsdom";
|
||||||
import {createHighlighter} from 'shiki'
|
import {createHighlighter} from "shiki";
|
||||||
|
|
||||||
const DEFAULT_THEME = 'github-dark-dimmed'
|
const DEFAULT_THEME = "github-dark-dimmed";
|
||||||
|
|
||||||
|
type SupportedLang = (typeof SUPPORTED_LANGS)[number];
|
||||||
|
|
||||||
const highlighter = await createHighlighter({
|
const highlighter = await createHighlighter({
|
||||||
themes: [DEFAULT_THEME],
|
themes: [DEFAULT_THEME],
|
||||||
langs: [
|
langs: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
const SUPPORTED_LANGS = [
|
||||||
"bash",
|
"bash",
|
||||||
"json",
|
"json",
|
||||||
"yaml",
|
"yaml",
|
||||||
@@ -23,98 +28,179 @@ const highlighter = await createHighlighter({
|
|||||||
"python",
|
"python",
|
||||||
"go",
|
"go",
|
||||||
"dockerfile",
|
"dockerfile",
|
||||||
"nginx"
|
"nginx",
|
||||||
]
|
] as const;
|
||||||
})
|
|
||||||
|
|
||||||
const resolveLang = (lang: string) => {
|
const loadedLangs = new Set<string>(["text"]);
|
||||||
const supported = highlighter.getLoadedLanguages?.() || []
|
|
||||||
if (!lang) return 'text'
|
|
||||||
if (supported.includes(lang)) return lang
|
|
||||||
return 'text'
|
|
||||||
}
|
|
||||||
|
|
||||||
export const processHtmlWithJsdom = async (rawHtml: string) => {
|
const supportedSet = new Set<string>(SUPPORTED_LANGS);
|
||||||
|
|
||||||
const dom = new JSDOM(rawHtml)
|
const LANG_MAP: Record<string, string> = {
|
||||||
const document = dom.window.document
|
markup: "html",
|
||||||
|
html: "html",
|
||||||
|
};
|
||||||
|
|
||||||
// 高亮处理代码块
|
const normalizeLang = (lang: string): string => {
|
||||||
const codeBlocks = document.querySelectorAll('pre code')
|
return LANG_MAP[lang] || lang;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ensureLangLoaded = async (lang: string): Promise<string> => {
|
||||||
|
if (lang === "text" || loadedLangs.has(lang)) return lang;
|
||||||
|
if (!supportedSet.has(lang)) return "text";
|
||||||
|
try {
|
||||||
|
await highlighter.loadLanguage(lang as SupportedLang);
|
||||||
|
loadedLangs.add(lang);
|
||||||
|
return lang;
|
||||||
|
} catch {
|
||||||
|
return "text";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
async function processCodeBlocks(document: Document) {
|
||||||
|
const codeBlocks = document.querySelectorAll("pre code");
|
||||||
|
|
||||||
for (const codeBlock of codeBlocks) {
|
for (const codeBlock of codeBlocks) {
|
||||||
const preEl = codeBlock.parentElement
|
const preEl = codeBlock.parentElement;
|
||||||
if (!preEl || preEl.tagName !== 'PRE') continue
|
if (!preEl || preEl.tagName !== "PRE") continue;
|
||||||
|
|
||||||
const codeContent = codeBlock.textContent || ''
|
const codeContent = codeBlock.textContent || "";
|
||||||
let lang = 'text'
|
let rawLang = "text";
|
||||||
for (const cls of codeBlock.classList) {
|
for (const cls of preEl.classList) {
|
||||||
if (cls.startsWith('language-')) {
|
if (cls.startsWith("language-")) {
|
||||||
lang = cls.slice('language-'.length)
|
rawLang = cls.slice("language-".length);
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lang = resolveLang(lang)
|
const lang = normalizeLang(rawLang);
|
||||||
|
|
||||||
|
const loadedLang = await ensureLangLoaded(lang);
|
||||||
|
|
||||||
// 高亮
|
|
||||||
const highlighted = highlighter.codeToHtml(codeContent, {
|
const highlighted = highlighter.codeToHtml(codeContent, {
|
||||||
lang,
|
lang: loadedLang,
|
||||||
theme: DEFAULT_THEME,
|
theme: DEFAULT_THEME,
|
||||||
})
|
});
|
||||||
|
|
||||||
// 替换 DOM
|
// 替换 DOM
|
||||||
const wrapper = document.createElement('div')
|
const wrapper = document.createElement("div");
|
||||||
wrapper.innerHTML = highlighted.trim()
|
wrapper.innerHTML = highlighted.trim();
|
||||||
|
|
||||||
const newNode = wrapper.firstElementChild
|
const newNode = wrapper.firstElementChild;
|
||||||
if (newNode && preEl.parentNode) {
|
if (newNode && preEl.parentNode) {
|
||||||
const container = document.createElement('div')
|
const container = document.createElement("div");
|
||||||
container.className = 'code-block'
|
container.className = "code-block";
|
||||||
|
|
||||||
const header = document.createElement('div')
|
const header = document.createElement("div");
|
||||||
header.className = 'code-header'
|
header.className = "code-header";
|
||||||
|
|
||||||
const headerLeft = document.createElement('div')
|
const headerLeft = document.createElement("div");
|
||||||
headerLeft.className = 'code-header-left'
|
headerLeft.className = "code-header-left";
|
||||||
|
|
||||||
const headerRight = document.createElement('div')
|
const headerRight = document.createElement("div");
|
||||||
headerRight.className = 'code-header-right'
|
headerRight.className = "code-header-right";
|
||||||
|
|
||||||
// 装饰点
|
// 装饰点
|
||||||
const actions = document.createElement('div')
|
const actions = document.createElement("div");
|
||||||
actions.className = 'code-actions'
|
actions.className = "code-actions";
|
||||||
|
|
||||||
const close = document.createElement('span')
|
const close = document.createElement("span");
|
||||||
close.className = 'dot close'
|
close.className = "dot close";
|
||||||
|
|
||||||
const minimize = document.createElement('span')
|
const minimize = document.createElement("span");
|
||||||
minimize.className = 'dot minimize'
|
minimize.className = "dot minimize";
|
||||||
|
|
||||||
const maximize = document.createElement('span')
|
const maximize = document.createElement("span");
|
||||||
maximize.className = 'dot maximize'
|
maximize.className = "dot maximize";
|
||||||
|
|
||||||
actions.append(close, minimize, maximize)
|
actions.append(close, minimize, maximize);
|
||||||
|
|
||||||
// 显示语言
|
// 显示语言
|
||||||
const langDisplay = document.createElement('div')
|
const langDisplay = document.createElement("div");
|
||||||
langDisplay.className = 'code-language'
|
langDisplay.className = "code-language";
|
||||||
langDisplay.textContent = lang ? lang : 'text'
|
langDisplay.textContent = lang ? lang : "text";
|
||||||
|
|
||||||
const copyBtn = document.createElement('div')
|
const copyBtn = document.createElement("div");
|
||||||
copyBtn.className = 'code-copy-btn'
|
copyBtn.className = "code-copy-btn";
|
||||||
copyBtn.textContent = '复制代码'
|
copyBtn.textContent = "复制代码";
|
||||||
|
|
||||||
headerLeft.append(actions, langDisplay)
|
headerLeft.append(actions, langDisplay);
|
||||||
headerRight.append(copyBtn)
|
headerRight.append(copyBtn);
|
||||||
|
|
||||||
header.append(headerLeft, headerRight)
|
header.append(headerLeft, headerRight);
|
||||||
|
|
||||||
container.append(header, newNode)
|
container.append(header, newNode);
|
||||||
|
|
||||||
preEl.parentNode.replaceChild(container, preEl)
|
preEl.parentNode.replaceChild(container, preEl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dom.serialize()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
||||||
|
|
||||||
|
export interface TocNode {
|
||||||
|
level: HeadingLevel;
|
||||||
|
id: string;
|
||||||
|
text: string;
|
||||||
|
element: HTMLHeadingElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createHeadingId(text: string, doc: Document): string {
|
||||||
|
const base = text.trim() || "heading";
|
||||||
|
|
||||||
|
let id = base;
|
||||||
|
let index = 1;
|
||||||
|
|
||||||
|
while (doc.getElementById(id)) {
|
||||||
|
id = `${base}-${index++}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getToc(document: Document): TocNode[] {
|
||||||
|
const headings = Array.from(
|
||||||
|
document.querySelectorAll<HTMLHeadingElement>("h1, h2, h3, h4, h5, h6"),
|
||||||
|
);
|
||||||
|
|
||||||
|
const result: TocNode[] = [];
|
||||||
|
|
||||||
|
for (const element of headings) {
|
||||||
|
const level = Number(element.tagName.slice(1)) as HeadingLevel;
|
||||||
|
|
||||||
|
const id =
|
||||||
|
element.id || createHeadingId(element.textContent ?? "", document);
|
||||||
|
|
||||||
|
element.id = id;
|
||||||
|
|
||||||
|
const node: TocNode = {
|
||||||
|
level,
|
||||||
|
id,
|
||||||
|
text: element.textContent?.trim() ?? "",
|
||||||
|
element,
|
||||||
|
};
|
||||||
|
result.push(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
type ParseResult = {
|
||||||
|
html: string;
|
||||||
|
toc: TocNode[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const processHtmlWithJsdom = async (
|
||||||
|
rawHtml: string,
|
||||||
|
): Promise<ParseResult> => {
|
||||||
|
const dom = new JSDOM(rawHtml);
|
||||||
|
const document = dom.window.document;
|
||||||
|
|
||||||
|
await processCodeBlocks(document);
|
||||||
|
|
||||||
|
const toc = getToc(document)
|
||||||
|
|
||||||
|
return {
|
||||||
|
html: document.body.innerHTML,
|
||||||
|
toc,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -2,6 +2,17 @@
|
|||||||
import Layout from "@/layouts/Layout.astro";
|
import Layout from "@/layouts/Layout.astro";
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout title="404" description="这里什么也没有发现~">
|
<Layout title="404" description="这里什么也没有">
|
||||||
|
<div class="not-found">
|
||||||
|
<h1>404 NOT FOUND</h1>
|
||||||
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.not-found{
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ const {data} = await http.get<ApiResponse<Archive>>("posts/archives");
|
|||||||
}
|
}
|
||||||
|
|
||||||
.post-date {
|
.post-date {
|
||||||
color: var(--text-tertiary);
|
color: var(--text-meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-title {
|
.post-title {
|
||||||
@@ -107,19 +107,29 @@ const {data} = await http.get<ApiResponse<Archive>>("posts/archives");
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
|
font-size: 16px;
|
||||||
|
text-underline-offset: 4px;
|
||||||
|
line-height: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-title:hover{
|
.post-title:hover{
|
||||||
|
color: var(--text-title-hover);
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-cat {
|
.post-cat {
|
||||||
color: var(--text-tertiary);
|
color: var(--text-meta);
|
||||||
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 640px) {
|
@media (max-width: 640px) {
|
||||||
.year-title{
|
.year-title{
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post-title{
|
||||||
|
font-size: 15px;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,20 +1,72 @@
|
|||||||
---
|
---
|
||||||
|
import ContributionHeatmap from "@/components/ContributionHeatmap.astro";
|
||||||
|
import { createHttp } from "@/lib/request.ts";
|
||||||
|
import type { HeatmapPoint } from "@/types/stats.ts";
|
||||||
|
|
||||||
const noindex = true;
|
const noindex = true;
|
||||||
|
|
||||||
|
// 与接口 https://admin.ua42.com/api/stats/gitea/x/heatmap 对应
|
||||||
|
const GITEA_USER = "x";
|
||||||
|
|
||||||
|
let heatmap: HeatmapPoint[] = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { data } = await createHttp().get<ApiResponse<HeatmapPoint[]>>(
|
||||||
|
`stats/gitea/${GITEA_USER}/heatmap`,
|
||||||
|
{
|
||||||
|
timeout: 5000,
|
||||||
|
retry: 0,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (Array.isArray(data)) heatmap = data;
|
||||||
|
} catch (error) {
|
||||||
|
// 统计接口不可用时不影响入口页展示
|
||||||
|
console.error("[embed/gitea] 热力图数据获取失败", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
const entries = [
|
||||||
|
{ label: "博客地址", desc: "ua42.com", href: "https://ua42.com" },
|
||||||
|
{
|
||||||
|
label: "博客管理后台",
|
||||||
|
desc: "admin.ua42.com · 支持游客查看",
|
||||||
|
href: "https://admin.ua42.com",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "仓库地址",
|
||||||
|
desc: "git.ua42.com/beggin",
|
||||||
|
href: "https://git.ua42.com/beggin",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "博客服务端仓库",
|
||||||
|
desc: "git.ua42.com/beggin/blog-server",
|
||||||
|
href: "https://git.ua42.com/beggin/blog-server",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "博客服务端 API 文档",
|
||||||
|
desc: "dev.ua42.com/docs",
|
||||||
|
href: "https://dev.ua42.com/docs/server-documentation.html",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Panda Dock",
|
||||||
|
desc: "github.com/forestRhapsody/panda-dock",
|
||||||
|
href: "https://github.com/forestRhapsody/panda-dock",
|
||||||
|
},
|
||||||
|
];
|
||||||
---
|
---
|
||||||
|
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8"/>
|
<meta charset="UTF-8" />
|
||||||
<meta
|
<meta
|
||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
|
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
|
||||||
/>
|
/>
|
||||||
<link rel="icon" type="image/svg+xml" href="/favicon.ico"/>
|
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
|
||||||
<meta name="generator" content={Astro.generator}/>
|
<meta name="generator" content={Astro.generator} />
|
||||||
<title>Gitea 入口</title>
|
<title>Gitea 入口</title>
|
||||||
<meta name="theme-color" content="#ffffff"/>
|
<meta name="theme-color" content="#ffffff" />
|
||||||
<meta name="robots" content="noindex, nofollow">
|
<meta name="robots" content="noindex, nofollow" />
|
||||||
<style>
|
<style>
|
||||||
@import "modern-normalize";
|
@import "modern-normalize";
|
||||||
|
|
||||||
@@ -27,7 +79,9 @@ const noindex = true;
|
|||||||
--primary: #4f6df5;
|
--primary: #4f6df5;
|
||||||
}
|
}
|
||||||
|
|
||||||
* {
|
*,
|
||||||
|
*::before,
|
||||||
|
*::after {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,104 +90,165 @@ const noindex = true;
|
|||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
background: var(--bg);
|
background: var(--bg);
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
font-family:
|
||||||
|
system-ui,
|
||||||
|
-apple-system,
|
||||||
|
"Segoe UI",
|
||||||
|
"PingFang SC",
|
||||||
|
"Microsoft YaHei",
|
||||||
|
sans-serif;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-container {
|
.page-container {
|
||||||
height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
padding: 24px 24px 24px 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.gitea-card {
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 520px;
|
max-width: 900px;
|
||||||
background: var(--card-bg);
|
min-height: 100vh;
|
||||||
border: 1px solid var(--border);
|
margin: 0 auto;
|
||||||
border-radius: 10px;
|
|
||||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.gitea-card__title {
|
|
||||||
padding: 14px 20px;
|
|
||||||
font-size: 15px;
|
|
||||||
font-weight: 600;
|
|
||||||
border-bottom: 1px solid var(--border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.gitea-content {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 28px;
|
||||||
|
padding: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea-item {
|
.section {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section__head {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: baseline;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
gap: 16px;
|
gap: 12px;
|
||||||
padding: 13px 20px;
|
margin-bottom: 10px;
|
||||||
font-size: 14px;
|
padding: 0 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea-item + .gitea-item {
|
.section__title {
|
||||||
border-top: 1px solid var(--border);
|
margin: 0;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea-item:hover {
|
.section__meta {
|
||||||
background: #fafbfc;
|
font-size: 12px;
|
||||||
}
|
|
||||||
|
|
||||||
.gitea-item__label {
|
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea-item__link {
|
.entry-grid {
|
||||||
color: var(--primary);
|
display: grid;
|
||||||
text-decoration: none;
|
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||||
white-space: nowrap;
|
gap: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea-item__link:hover {
|
.entry {
|
||||||
text-decoration: underline;
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
padding: 14px 40px 14px 16px;
|
||||||
|
background: var(--card-bg);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
transition:
|
||||||
|
border-color 0.15s ease,
|
||||||
|
box-shadow 0.15s ease,
|
||||||
|
transform 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.entry:hover {
|
||||||
|
border-color: #c7d2fe;
|
||||||
|
box-shadow: 0 4px 14px rgba(79, 109, 245, 0.12);
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.entry__label {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.entry__desc {
|
||||||
|
overflow: hidden;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.entry__arrow {
|
||||||
|
position: absolute;
|
||||||
|
top: 14px;
|
||||||
|
right: 16px;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
transition:
|
||||||
|
color 0.15s ease,
|
||||||
|
transform 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.entry:hover .entry__arrow {
|
||||||
|
color: var(--primary);
|
||||||
|
transform: translate(1px, -1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
width: 100%;
|
||||||
|
background: var(--card-bg);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
.page-container {
|
||||||
|
gap: 20px;
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="page-container">
|
<div class="page-container">
|
||||||
<div class="gitea-card">
|
<section class="section">
|
||||||
<div class="gitea-card__title">常用入口</div>
|
<div class="section__head">
|
||||||
<div class="gitea-content">
|
<h2 class="section__title">常用入口</h2>
|
||||||
<div class="gitea-item">
|
|
||||||
<span class="gitea-item__label">博客地址</span>
|
|
||||||
<a class="gitea-item__link" target="_blank" href="https://ua42.com">点击访问</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="entry-grid">
|
||||||
|
{entries.map(({ label, desc, href }) => (
|
||||||
|
<a
|
||||||
|
class="entry"
|
||||||
|
href={href}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<span class="entry__label">{label}</span>
|
||||||
|
<span class="entry__desc">{desc}</span>
|
||||||
|
<span class="entry__arrow" aria-hidden="true">
|
||||||
|
↗
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<div class="gitea-item">
|
{heatmap.length > 0 && (
|
||||||
<span class="gitea-item__label">博客管理后台(支持游客查看)</span>
|
<section class="section">
|
||||||
<a class="gitea-item__link" target="_blank" href="https://admin.ua42.com">点击访问</a>
|
<div class="section__head">
|
||||||
|
<h2 class="section__title">代码贡献</h2>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="card">
|
||||||
<div class="gitea-item">
|
<ContributionHeatmap points={heatmap} />
|
||||||
<span class="gitea-item__label">仓库地址</span>
|
|
||||||
<a class="gitea-item__link" target="_blank" href="https://git.ua42.com/beggin">点击访问</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
</section>
|
||||||
<div class="gitea-item">
|
)}
|
||||||
<span class="gitea-item__label">博客服务端仓库</span>
|
|
||||||
<a class="gitea-item__link" target="_blank" href="https://git.ua42.com/beggin/blog-server">点击访问</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
</body>
|
||||||
<div class="gitea-item">
|
|
||||||
<span class="gitea-item__label">博客服务端 API文档</span>
|
|
||||||
<a class="gitea-item__link" target="_blank" href="https://dev.ua42.com/docs/server-documentation.html">点击访问</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ if (isNaN(pageInt) || pageInt <= 1) {
|
|||||||
return Astro.redirect("/");
|
return Astro.redirect("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
const {postPageSize,description} = siteConfig;
|
const {postPageSize, description} = siteConfig;
|
||||||
|
|
||||||
const http = createHttp(Astro.request.headers);
|
const http = createHttp(Astro.request.headers);
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,14 @@ import "@/styles/github-markdown.css";
|
|||||||
import "@/styles/github-markdown-reset.css";
|
import "@/styles/github-markdown-reset.css";
|
||||||
import "photoswipe/dist/photoswipe.css";
|
import "photoswipe/dist/photoswipe.css";
|
||||||
|
|
||||||
import Layout from '@/layouts/Layout.astro';
|
import Layout from "@/layouts/Layout.astro";
|
||||||
import {createHttp} from "@/lib/request.ts";
|
import Toc from "@/components/Post/Toc.astro";
|
||||||
import type {Post} from "@/types";
|
import { createHttp } from "@/lib/request.ts";
|
||||||
import {processHtmlWithJsdom} from "@/lib/processHtml.ts";
|
import type { Post } from "@/types";
|
||||||
import {siteConfig} from '@/consts'
|
import { processHtmlWithJsdom } from "@/lib/processHtml.ts";
|
||||||
import {formatDatetime} from "@/lib/format.ts";
|
import { formatDatetime } from "@/lib/format.ts";
|
||||||
|
|
||||||
const {siteTitle} = siteConfig
|
const { slug } = Astro.params;
|
||||||
|
|
||||||
const {slug} = Astro.params;
|
|
||||||
|
|
||||||
const http = createHttp(Astro.request.headers);
|
const http = createHttp(Astro.request.headers);
|
||||||
|
|
||||||
@@ -25,11 +23,12 @@ try {
|
|||||||
return Astro.redirect("/404");
|
return Astro.redirect("/404");
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = await processHtmlWithJsdom(data.content);
|
const { html, toc } = await processHtmlWithJsdom(data.content);
|
||||||
const published_at = formatDatetime(data.published_at, "YYYY.MM.DD");
|
const published_at = formatDatetime(data.published_at, "YYYY.MM.DD");
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout title={data.title} description={data.summary}>
|
<Layout title={data.title} description={data.summary}>
|
||||||
|
<div class="post-wrap">
|
||||||
<article>
|
<article>
|
||||||
<div class="meta">
|
<div class="meta">
|
||||||
<div class="meta-left">
|
<div class="meta-left">
|
||||||
@@ -39,38 +38,57 @@ const published_at = formatDatetime(data.published_at, "YYYY.MM.DD");
|
|||||||
|
|
||||||
<div class="meta-view-count">{data.view_count} 次阅读</div>
|
<div class="meta-view-count">{data.view_count} 次阅读</div>
|
||||||
</div>
|
</div>
|
||||||
<h1>{data.title}</h1>
|
<h1 class="title">{data.title}</h1>
|
||||||
|
|
||||||
|
{
|
||||||
|
data.cover && (
|
||||||
|
<div>
|
||||||
|
<img class="cover" src={data.cover} alt={data.title} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
<p class="summary">{data.summary}</p>
|
<p class="summary">{data.summary}</p>
|
||||||
|
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
|
|
||||||
<div class="markdown-body" data-color-mode="dark" set:html={content}/>
|
<div class="markdown-body" data-color-mode="dark" set:html={html} />
|
||||||
|
|
||||||
{
|
{
|
||||||
data.tags.length > 0 &&
|
data.tags.length > 0 && (
|
||||||
<div class="tags">
|
<div class="tags">
|
||||||
{data.tags.map(tag => <span>{tag.name}</span>)}
|
{data.tags.map((tag) => (
|
||||||
|
<span>{tag.name}</span>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
{toc.length > 0 && <Toc toc={toc} />}
|
||||||
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
article {
|
.post-wrap {
|
||||||
width: 100%;
|
position: relative;
|
||||||
margin: 0 auto;
|
|
||||||
padding: 24px 0 24px 0;
|
|
||||||
flex: 1;
|
flex: 1;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cover {
|
||||||
|
width: 100%;
|
||||||
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.meta {
|
.meta {
|
||||||
color: var(--text-meta);
|
color: var(--text-meta);
|
||||||
font-size: 13px;
|
font-size: 14px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.meta-left {
|
.meta-left {
|
||||||
@@ -79,21 +97,23 @@ const published_at = formatDatetime(data.published_at, "YYYY.MM.DD");
|
|||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.meta-view-count:hover{
|
.meta-view-count:hover {
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
.title {
|
||||||
font-size: 28px;
|
font-size: 36px;
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
font-weight: 400;
|
margin-bottom: 20px;
|
||||||
margin: 20px 0 20px;
|
color: var(--text-primary);
|
||||||
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.summary {
|
.summary {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
margin-bottom: 24px;
|
margin-bottom: 20px;
|
||||||
color: var(--text-meta);
|
color: var(--text-summary);
|
||||||
|
line-height: 1.4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.divider {
|
.divider {
|
||||||
@@ -101,9 +121,9 @@ const published_at = formatDatetime(data.published_at, "YYYY.MM.DD");
|
|||||||
}
|
}
|
||||||
|
|
||||||
.markdown-body {
|
.markdown-body {
|
||||||
margin: 24px 0 24px 0;
|
margin-top: 24px;
|
||||||
line-height: 1.8;
|
line-height: 1.8;
|
||||||
font-size: 15px;
|
font-size: 16px;
|
||||||
color: var(--article-text-color);
|
color: var(--article-text-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,11 +136,17 @@ const published_at = formatDatetime(data.published_at, "YYYY.MM.DD");
|
|||||||
|
|
||||||
.tags span {
|
.tags span {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #57606a;
|
color: var(--text-secondary);
|
||||||
border: var(--border-primary);
|
border: var(--border-primary);
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
padding: 8px 16px;
|
padding: 8px 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
.title {
|
||||||
|
font-size: 30px;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -128,17 +154,19 @@ const published_at = formatDatetime(data.published_at, "YYYY.MM.DD");
|
|||||||
import ClipboardJS from "clipboard";
|
import ClipboardJS from "clipboard";
|
||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
const article = document.querySelector("article")!;
|
const article = document.querySelector(".markdown-body")!;
|
||||||
const images = Array.from(article.querySelectorAll("img"));
|
const images = Array.from(article.querySelectorAll("img"));
|
||||||
|
|
||||||
|
if (images.length === 0) return;
|
||||||
|
|
||||||
const waitImageLoaded = (img: HTMLImageElement) => {
|
const waitImageLoaded = (img: HTMLImageElement) => {
|
||||||
if (img.complete && img.naturalWidth > 0 && img.naturalHeight > 0) {
|
if (img.complete && img.naturalWidth > 0 && img.naturalHeight > 0) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise<void>((resolve) => {
|
||||||
img.addEventListener("load", () => resolve(), {once: true});
|
img.addEventListener("load", () => resolve(), { once: true });
|
||||||
img.addEventListener("error", () => resolve(), {once: true});
|
img.addEventListener("error", () => resolve(), { once: true });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -164,7 +192,7 @@ const published_at = formatDatetime(data.published_at, "YYYY.MM.DD");
|
|||||||
);
|
);
|
||||||
|
|
||||||
const lightbox = new PhotoSwipeLightbox({
|
const lightbox = new PhotoSwipeLightbox({
|
||||||
gallery: "article",
|
gallery: ".markdown-body",
|
||||||
children: "a[data-pswp-width]",
|
children: "a[data-pswp-width]",
|
||||||
pswpModule: () => import("photoswipe"),
|
pswpModule: () => import("photoswipe"),
|
||||||
|
|
||||||
@@ -184,7 +212,6 @@ const published_at = formatDatetime(data.published_at, "YYYY.MM.DD");
|
|||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
|
||||||
const copyTimers = new WeakMap<HTMLElement, ReturnType<typeof setTimeout>>();
|
const copyTimers = new WeakMap<HTMLElement, ReturnType<typeof setTimeout>>();
|
||||||
|
|
||||||
// 代码块复制功能
|
// 代码块复制功能
|
||||||
@@ -192,7 +219,7 @@ const published_at = formatDatetime(data.published_at, "YYYY.MM.DD");
|
|||||||
text: (el) => {
|
text: (el) => {
|
||||||
const sibling = el.closest(".code-header")?.nextElementSibling;
|
const sibling = el.closest(".code-header")?.nextElementSibling;
|
||||||
return sibling?.textContent.trim() || "";
|
return sibling?.textContent.trim() || "";
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
clipboard.on("success", (e) => {
|
clipboard.on("success", (e) => {
|
||||||
|
|||||||
@@ -8,27 +8,6 @@ a {
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
::-webkit-scrollbar {
|
|
||||||
width: 8px;
|
|
||||||
height: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 滚动条轨道 */
|
|
||||||
::-webkit-scrollbar-track {
|
|
||||||
background: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 滚动条滑块 */
|
|
||||||
::-webkit-scrollbar-thumb {
|
|
||||||
background: #cbd5e1;
|
|
||||||
border-radius: 999px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 鼠标悬停 */
|
|
||||||
::-webkit-scrollbar-thumb:hover {
|
|
||||||
background: #94a3b8;
|
|
||||||
}
|
|
||||||
|
|
||||||
ul,li{
|
ul,li{
|
||||||
list-style: none;
|
list-style: none;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
.markdown-body pre code {
|
.markdown-body pre code {
|
||||||
font-size: 1.15em;
|
font-size: 14px;
|
||||||
|
line-height: 1.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown-body h1,
|
.markdown-body h1,
|
||||||
@@ -19,7 +20,7 @@
|
|||||||
|
|
||||||
.markdown-body .highlight pre,
|
.markdown-body .highlight pre,
|
||||||
.markdown-body pre {
|
.markdown-body pre {
|
||||||
border-radius: 0 0 6px 6px;
|
border-radius: 0 0 8px 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown-body img {
|
.markdown-body img {
|
||||||
@@ -27,19 +28,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.code-block {
|
.code-block {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.code-header {
|
.code-header {
|
||||||
height: 36px;
|
height: 36px;
|
||||||
background: #f5f5f5;
|
background: var(--code-block-header-bg);
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 0 12px;
|
padding: 0 12px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
border-radius: 6px 6px 0 0;
|
border-radius: 8px 8px 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.code-header-left {
|
.code-header-left {
|
||||||
@@ -80,5 +80,5 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.code-copy-btn:hover {
|
.code-copy-btn:hover {
|
||||||
color: #1d4ed8;
|
color: var(--code-block-copy-btn-hover-color);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,21 +2,60 @@
|
|||||||
@import "css-reset.css";
|
@import "css-reset.css";
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
|
--font-family:
|
||||||
|
-apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
|
||||||
|
"Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial,
|
||||||
|
sans-serif;
|
||||||
--layout-width: 760px;
|
--layout-width: 760px;
|
||||||
|
|
||||||
|
--background: #ffffff;
|
||||||
--border-primary: 1px solid #dcdcdc;
|
--border-primary: 1px solid #dcdcdc;
|
||||||
--border-secondary: 1px solid #eee;
|
--border-secondary: 1px solid #eee;
|
||||||
|
--text-primary: #030712;
|
||||||
--text-primary: #24292e;
|
--text-secondary: #3f3f46;
|
||||||
--text-secondary: #4b5563;
|
|
||||||
--text-tertiary: #9ca3af;
|
|
||||||
--text-disabled: #d1d5db;
|
--text-disabled: #d1d5db;
|
||||||
--text-meta: #71717a;
|
--text-meta: #71717a;
|
||||||
--font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
--article-text-color: #1e1e1e;
|
||||||
--article-text-color: #404040;
|
--text-title-hover: #000;
|
||||||
|
--code-block-header-bg: #f5f5f4;
|
||||||
|
--code-block-copy-btn-hover-color: #6b7280;
|
||||||
|
--text-summary: #000;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
|
--background: #0a0a0a;
|
||||||
|
--border-primary: 1px solid #52525b;
|
||||||
|
--border-secondary: 1px solid #525252;
|
||||||
|
--text-primary: #e4e4e7;
|
||||||
|
--text-secondary: #d1d5db;
|
||||||
|
--text-disabled: #6b7280;
|
||||||
|
--text-meta: #d4d4d8;
|
||||||
|
--article-text-color: #d4d4d8;
|
||||||
|
--text-title-hover: #fff;
|
||||||
|
--code-block-header-bg: #374151;
|
||||||
|
--code-block-copy-btn-hover-color: #9ca3af;
|
||||||
|
--text-summary: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 滚动条轨道 */
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 滚动条滑块 */
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
background: rgba(139, 139, 139, 0.5);
|
||||||
|
border-radius: 999px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 鼠标悬停 */
|
||||||
|
::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: rgba(139, 139, 139, 0.7);
|
||||||
}
|
}
|
||||||
|
|
||||||
html,
|
html,
|
||||||
@@ -26,4 +65,9 @@ body {
|
|||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
font-family: var(--font-family), serif;
|
font-family: var(--font-family), serif;
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
|
background: var(--background);
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
scroll-behavior: smooth;
|
||||||
}
|
}
|
||||||
|
|||||||
7
src/types/stats.ts
Normal file
7
src/types/stats.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
/** Gitea 贡献热力图接口返回的原始数据点 */
|
||||||
|
export type HeatmapPoint = {
|
||||||
|
/** Unix 秒级时间戳 */
|
||||||
|
timestamp: number
|
||||||
|
/** 该时间点产生的贡献次数 */
|
||||||
|
contributions: number
|
||||||
|
}
|
||||||
@@ -13,8 +13,6 @@
|
|||||||
"@/*": [
|
"@/*": [
|
||||||
"src/*"
|
"src/*"
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
"jsx": "preserve",
|
|
||||||
"jsxImportSource": "solid-js"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user