mirror of
https://github.com/MCKero6423/fuwari.git
synced 2026-10-02 03:15:35 +00:00
Add files via upload
This commit is contained in:
1 parent
86cabacf25
commit
cd5ea0eea2
2 files changed
+155
-15
No files matched your search
@@ -1,12 +1,13 @@
|
||||
---
|
||||
import type { CollectionEntry } from "astro:content";
|
||||
import path from "node:path";
|
||||
import type { CollectionEntry } from "astro:content";
|
||||
import { Icon } from "astro-icon/components";
|
||||
import I18nKey from "../i18n/i18nKey";
|
||||
import { i18n } from "../i18n/translation";
|
||||
import { getDir } from "../utils/url-utils";
|
||||
import ImageWrapper from "./misc/ImageWrapper.astro";
|
||||
import PostMetadata from "./PostMeta.astro";
|
||||
import ImageWrapper from "./misc/ImageWrapper.astro";
|
||||
import { umamiConfig } from "../config";
|
||||
|
||||
interface Props {
|
||||
class?: string;
|
||||
@@ -16,7 +17,7 @@ interface Props {
|
||||
published: Date;
|
||||
updated?: Date;
|
||||
tags: string[];
|
||||
category: string | null;
|
||||
category: string;
|
||||
image: string;
|
||||
description: string;
|
||||
draft: boolean;
|
||||
@@ -34,6 +35,8 @@ const {
|
||||
description,
|
||||
style,
|
||||
} = Astro.props;
|
||||
|
||||
const isPinned = entry.data.pinned === true;
|
||||
const className = Astro.props.class;
|
||||
|
||||
const hasCover = image !== undefined && image !== null && image !== "";
|
||||
@@ -51,6 +54,11 @@ const { remarkPluginFrontmatter } = await entry.render();
|
||||
before:w-1 before:h-5 before:rounded-md before:bg-[var(--primary)]
|
||||
before:absolute before:top-[35px] before:left-[18px] before:hidden md:before:block
|
||||
">
|
||||
{isPinned && (
|
||||
<span class="inline-flex items-center mr-2 px-2 py-0.5 text-sm font-medium bg-[oklch(95%_0.2_var(--hue))] dark:bg-[oklch(25%_0.2_var(--hue))] text-[oklch(55%_0.2_var(--hue))] dark:text-[oklch(85%_0.2_var(--hue))] rounded">
|
||||
<Icon name="material-symbols:push-pin" class="mr-1 text-base" /> 置顶
|
||||
</span>
|
||||
)}
|
||||
{title}
|
||||
<Icon class="inline text-[2rem] text-[var(--primary)] md:hidden translate-y-0.5 absolute" name="material-symbols:chevron-right-rounded" ></Icon>
|
||||
<Icon class="text-[var(--primary)] text-[2rem] transition hidden md:inline absolute translate-y-0.5 opacity-0 group-hover:opacity-100 -translate-x-1 group-hover:translate-x-0" name="material-symbols:chevron-right-rounded"></Icon>
|
||||
@@ -64,14 +72,14 @@ const { remarkPluginFrontmatter } = await entry.render();
|
||||
{ description || remarkPluginFrontmatter.excerpt }
|
||||
</div>
|
||||
|
||||
<!-- word count and read time -->
|
||||
<!-- word count, read time and page views -->
|
||||
<div class="text-sm text-black/30 dark:text-white/30 flex gap-4 transition">
|
||||
<div>
|
||||
{remarkPluginFrontmatter.words} {" " + i18n(remarkPluginFrontmatter.words === 1 ? I18nKey.wordCount : I18nKey.wordsCount)}
|
||||
</div>
|
||||
<div>{remarkPluginFrontmatter.words} {" " + i18n(I18nKey.wordsCount)}</div>
|
||||
<div>|</div>
|
||||
<div>{remarkPluginFrontmatter.minutes} {" " + i18n(I18nKey.minutesCount)}</div>
|
||||
<div>|</div>
|
||||
<div>
|
||||
{remarkPluginFrontmatter.minutes} {" " + i18n(remarkPluginFrontmatter.minutes === 1 ? I18nKey.minuteCount : I18nKey.minutesCount)}
|
||||
<span class="text-50 text-sm font-medium" id={`page-views-${entry.slug}`}>加载中...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -83,6 +91,7 @@ const { remarkPluginFrontmatter } = await entry.render();
|
||||
"md:w-[var(--coverWidth)] relative md:absolute md:top-3 md:bottom-3 md:right-3 rounded-xl overflow-hidden active:scale-95"
|
||||
]} >
|
||||
<div class="absolute pointer-events-none z-10 w-full h-full group-hover:bg-black/30 group-active:bg-black/50 transition"></div>
|
||||
<!-- 封面图上的箭头 -->
|
||||
<div class="absolute pointer-events-none z-20 w-full h-full flex items-center justify-center ">
|
||||
<Icon name="material-symbols:chevron-right-rounded"
|
||||
class="transition opacity-0 group-hover:opacity-100 scale-50 group-hover:scale-100 text-white text-5xl">
|
||||
@@ -106,5 +115,67 @@ const { remarkPluginFrontmatter } = await entry.render();
|
||||
</div>
|
||||
<div class="transition border-t-[1px] border-dashed mx-6 border-black/10 dark:border-white/[0.15] last:border-t-0 md:hidden"></div>
|
||||
|
||||
<script define:vars={{ entry, umamiConfig }}>
|
||||
// 获取文章浏览量统计
|
||||
async function fetchPostCardViews(slug) {
|
||||
if (!umamiConfig.enable) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 调用全局工具获取 Umami 分享数据
|
||||
const { websiteId, token } = await getUmamiShareData(umamiConfig.baseUrl, umamiConfig.shareId);
|
||||
|
||||
// 第二步:获取统计数据
|
||||
const currentTimestamp = Date.now();
|
||||
const statsUrl = `${umamiConfig.baseUrl}/api/websites/${websiteId}/stats?startAt=0&endAt=${currentTimestamp}&unit=hour&timezone=${encodeURIComponent(umamiConfig.timezone)}&url=%2Fposts%2F${slug}%2F&compare=false`;
|
||||
|
||||
const statsResponse = await fetch(statsUrl, {
|
||||
headers: {
|
||||
'x-umami-share-token': token
|
||||
}
|
||||
});
|
||||
|
||||
if (statsResponse.status === 401) {
|
||||
clearUmamiShareCache();
|
||||
return await fetchPostCardViews(slug);
|
||||
}
|
||||
|
||||
if (!statsResponse.ok) {
|
||||
throw new Error('获取统计数据失败');
|
||||
}
|
||||
|
||||
const statsData = await statsResponse.json();
|
||||
const pageViews = statsData.pageviews?.value || 0;
|
||||
const visits = statsData.visits?.value || 0;
|
||||
|
||||
const displayElement = document.getElementById(`page-views-${slug}`);
|
||||
if (displayElement) {
|
||||
displayElement.textContent = `浏览量 ${pageViews} · 访问数 ${visits}`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching page views for', slug, ':', error);
|
||||
const displayElement = document.getElementById(`page-views-${slug}`);
|
||||
if (displayElement) {
|
||||
displayElement.textContent = '统计不可用';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载完成后获取统计数据
|
||||
function initPostCardStats() {
|
||||
const slug = entry.slug;
|
||||
if (slug) {
|
||||
fetchPostCardViews(slug);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', initPostCardStats);
|
||||
} else {
|
||||
initPostCardStats();
|
||||
}
|
||||
</script>
|
||||
|
||||
<style define:vars={{coverWidth}}>
|
||||
</style>
|
||||
</style>
|
||||
@@ -2,17 +2,19 @@
|
||||
import { Icon } from "astro-icon/components";
|
||||
import I18nKey from "../i18n/i18nKey";
|
||||
import { i18n } from "../i18n/translation";
|
||||
import { getDir, url } from "../utils/url-utils";
|
||||
import { formatDateToYYYYMMDD } from "../utils/date-utils";
|
||||
import { getCategoryUrl, getTagUrl } from "../utils/url-utils";
|
||||
import { umamiConfig } from "../config";
|
||||
|
||||
interface Props {
|
||||
class: string;
|
||||
published: Date;
|
||||
updated?: Date;
|
||||
tags: string[];
|
||||
category: string | null;
|
||||
category: string;
|
||||
hideTagsForMobile?: boolean;
|
||||
hideUpdateDate?: boolean;
|
||||
slug?: string;
|
||||
}
|
||||
const {
|
||||
published,
|
||||
@@ -21,6 +23,7 @@ const {
|
||||
category,
|
||||
hideTagsForMobile = false,
|
||||
hideUpdateDate = false,
|
||||
slug,
|
||||
} = Astro.props;
|
||||
const className = Astro.props.class;
|
||||
---
|
||||
@@ -53,7 +56,7 @@ const className = Astro.props.class;
|
||||
<Icon name="material-symbols:book-2-outline-rounded" class="text-xl"></Icon>
|
||||
</div>
|
||||
<div class="flex flex-row flex-nowrap items-center">
|
||||
<a href={getCategoryUrl(category)} aria-label={`View all posts in the ${category} category`}
|
||||
<a href={url(`/archive/category/${category || 'uncategorized'}/`)} aria-label=`View all posts in the ${category} category`
|
||||
class="link-lg transition text-50 text-sm font-medium
|
||||
hover:text-[var(--primary)] dark:hover:text-[var(--primary)] whitespace-nowrap">
|
||||
{category || i18n(I18nKey.uncategorized)}
|
||||
@@ -70,13 +73,79 @@ const className = Astro.props.class;
|
||||
<div class="flex flex-row flex-nowrap items-center">
|
||||
{(tags && tags.length > 0) && tags.map((tag, i) => (
|
||||
<div class:list={[{"hidden": i == 0}, "mx-1.5 text-[var(--meta-divider)] text-sm"]}>/</div>
|
||||
<a href={getTagUrl(tag)} aria-label={`View all posts with the ${tag.trim()} tag`}
|
||||
<a href={url(`/archive/tag/${tag}/`)} aria-label=`View all posts with the ${tag} tag`
|
||||
class="link-lg transition text-50 text-sm font-medium
|
||||
hover:text-[var(--primary)] dark:hover:text-[var(--primary)] whitespace-nowrap">
|
||||
{tag.trim()}
|
||||
{tag}
|
||||
</a>
|
||||
))}
|
||||
{!(tags && tags.length > 0) && <div class="transition text-50 text-sm font-medium">{i18n(I18nKey.noTags)}</div>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- page views -->
|
||||
{slug && (
|
||||
<div class="flex items-center">
|
||||
<div class="meta-icon">
|
||||
<Icon name="material-symbols:visibility-outline-rounded" class="text-xl"></Icon>
|
||||
</div>
|
||||
<span class="text-50 text-sm font-medium" id="page-views-display">加载中...</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{slug && (
|
||||
<script define:vars={{ slug, umamiConfig }}>
|
||||
// 获取访问量统计
|
||||
async function fetchPageViews(isRetry = false) {
|
||||
if (!umamiConfig.enable) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 调用全局工具获取 Umami 分享数据
|
||||
const { websiteId, token } = await getUmamiShareData(umamiConfig.baseUrl, umamiConfig.shareId);
|
||||
|
||||
// 第二步:获取统计数据
|
||||
const currentTimestamp = Date.now();
|
||||
const statsUrl = `${umamiConfig.baseUrl}/api/websites/${websiteId}/stats?startAt=0&endAt=${currentTimestamp}&unit=hour&timezone=${encodeURIComponent(umamiConfig.timezone)}&url=%2Fposts%2F${slug}%2F&compare=false`;
|
||||
|
||||
const statsResponse = await fetch(statsUrl, {
|
||||
headers: {
|
||||
'x-umami-share-token': token
|
||||
}
|
||||
});
|
||||
|
||||
if (!statsResponse.ok) {
|
||||
if (statsResponse.status === 401 && !isRetry) {
|
||||
clearUmamiShareCache();
|
||||
return fetchPageViews(true);
|
||||
}
|
||||
throw new Error('获取统计数据失败');
|
||||
}
|
||||
|
||||
const statsData = await statsResponse.json();
|
||||
const pageViews = statsData.pageviews?.value || 0;
|
||||
const visits = statsData.visits?.value || 0;
|
||||
|
||||
const displayElement = document.getElementById('page-views-display');
|
||||
if (displayElement) {
|
||||
displayElement.textContent = `浏览量 ${pageViews} · 访问数 ${visits}`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching page views:', error);
|
||||
const displayElement = document.getElementById('page-views-display');
|
||||
if (displayElement) {
|
||||
displayElement.textContent = '统计不可用';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载完成后获取统计数据
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', fetchPageViews);
|
||||
} else {
|
||||
fetchPageViews();
|
||||
}
|
||||
</script>
|
||||
)}
|
||||
Reference in new issue
Block a user