diff --git a/public/style.css b/public/style.css
index 0352fbc..ae290d8 100644
--- a/public/style.css
+++ b/public/style.css
@@ -1977,6 +1977,18 @@ h1.entry-title {
color: #888888;
}
+.entry-census .bull {
+ margin: 0 5px;
+}
+
+.twikoo-views[hidden] {
+ display: none !important;
+}
+
+.twikoo-comments[hidden] {
+ display: none !important;
+}
+
.entry-header hr {
width: 30%;
height: 1px;
diff --git a/src/components/PostList.astro b/src/components/PostList.astro
index 4ac4656..33c8276 100644
--- a/src/components/PostList.astro
+++ b/src/components/PostList.astro
@@ -1,11 +1,14 @@
---
import type { PostListItem } from './PostListThumb.astro';
+import TwikooViews from './TwikooViews.astro';
+import config from '../../asky.config';
export interface Props {
posts: PostListItem[];
}
const { posts } = Astro.props;
+const showTwikooStats = Boolean((config.twikoo?.envId || '').trim());
function timeSince(date: string): string {
const past = new Date(date).getTime();
@@ -45,15 +48,25 @@ function timeSince(date: string): string {
))}
+
+{showTwikooStats && }
diff --git a/src/components/PostListThumb.astro b/src/components/PostListThumb.astro
index 4709f92..7b0de66 100644
--- a/src/components/PostListThumb.astro
+++ b/src/components/PostListThumb.astro
@@ -1,5 +1,7 @@
---
import { askyOption, bloginfo } from '../lib/options';
+import TwikooViews from './TwikooViews.astro';
+import config from '../../asky.config';
export interface PostListItem {
id: string;
@@ -23,6 +25,7 @@ const focusLogo = askyOption('focus_logo') || '/images/avatar.jpg';
const showLike = askyOption('post_like') === 'yes';
const blogName = bloginfo('name');
const blogUrl = bloginfo('url');
+const showTwikooStats = Boolean((config.twikoo?.envId || '').trim());
function timeSince(date: string): string {
const past = new Date(date).getTime();
@@ -69,8 +72,16 @@ function timeSince(date: string): string {
{post.excerpt}
))}
+
+{showTwikooStats && }
diff --git a/src/components/TwikooViews.astro b/src/components/TwikooViews.astro
new file mode 100644
index 0000000..02071e4
--- /dev/null
+++ b/src/components/TwikooViews.astro
@@ -0,0 +1,166 @@
+---
+import config from '../../asky.config';
+
+export interface Props {
+ incrementUrl?: string;
+ title?: string;
+}
+
+const { incrementUrl = '', title = '' } = Astro.props;
+const envId = (config.twikoo?.envId || '').replace(/\/$/, '');
+---
+
+{envId && (
+
+)}
diff --git a/src/layouts/BaseLayout.astro b/src/layouts/BaseLayout.astro
index 26d73f9..3b51444 100644
--- a/src/layouts/BaseLayout.astro
+++ b/src/layouts/BaseLayout.astro
@@ -18,6 +18,7 @@ export interface Props {
patternAuthorUrl?: string;
patternAvatar?: string;
patternMeta?: string;
+ patternViewsUrl?: string;
/** 自定义 body class */
bodyClass?: string;
}
@@ -34,6 +35,7 @@ const {
patternAuthorUrl = '/',
patternAvatar,
patternMeta,
+ patternViewsUrl,
bodyClass = ''
} = Astro.props;
@@ -141,6 +143,14 @@ const patternHeaderClass = `pattern-header${patternSingle ? ' single-header' : '
{patternMeta}
>
)}
+ {patternViewsUrl && (
+ <>
+ {(patternAuthor || patternMeta) && ·}
+
+ 热度
+
+ >
+ )}
>
) : (
diff --git a/src/pages/posts/[slug].astro b/src/pages/posts/[slug].astro
index 8f7e627..d5a0093 100644
--- a/src/pages/posts/[slug].astro
+++ b/src/pages/posts/[slug].astro
@@ -7,8 +7,10 @@ import AuthorProfile from '../../components/AuthorProfile.astro';
import PostNextPrev from '../../components/PostNextPrev.astro';
import ShareLike from '../../components/ShareLike.astro';
import Comments from '../../components/Comments.astro';
+import TwikooViews from '../../components/TwikooViews.astro';
import { askyOption, isOptionOn } from '../../lib/options';
import { getCollection } from 'astro:content';
+import config from '../../../asky.config';
export async function getStaticPaths() {
const all = (await getCollection('posts')).sort(
@@ -35,9 +37,11 @@ const showPattern = isOptionOn('patternimg');
const buildTime = post.data.date.toLocaleString('zh-CN');
const tags = post.data.tags ?? [];
const fullUrl = new URL(`/posts/${post.slug}`, Astro.site ?? 'https://example.com').toString();
+const postPath = `/posts/${post.slug}/`;
const patternImg = showPattern ? undefined : (post.data.thumbnail ?? '/images/hd.jpg');
const authorName = post.data.author ?? 'Admin';
const authorAvatar = askyOption('focus_logo') || '/images/avatar.jpg';
+const showTwikooViews = Boolean((config.twikoo?.envId || '').trim());
---
@@ -63,6 +68,14 @@ const authorAvatar = askyOption('focus_logo') || '/images/avatar.jpg';
{post.data.title}
{buildTime}
+ {showTwikooViews && (
+ <>
+ ·
+
+ 热度
+
+ >
+ )}
@@ -89,6 +102,7 @@ const authorAvatar = askyOption('focus_logo') || '/images/avatar.jpg';
+ {showTwikooViews && }