feat: add a calendar for sidebar.

This commit is contained in:
Yufan Sheng 2024-11-26 18:08:33 +08:00
parent b1ddb5de38
commit b2163ef1b2
Signed by: syhily
GPG Key ID: 9D18A22A7DCD5A9B
9 changed files with 74 additions and 39 deletions

View File

@ -103,6 +103,7 @@
"opendal", "opendal",
"oppo", "oppo",
"opposans", "opposans",
"owspace",
"pandiyan", "pandiyan",
"penheulim", "penheulim",
"pilgi", "pilgi",

View File

@ -65,6 +65,7 @@ const Options = z
post: z.number().default(6), post: z.number().default(6),
comment: z.number().default(0), comment: z.number().default(0),
tag: z.number().default(20), tag: z.number().default(20),
calendar: z.boolean().default(false),
}), }),
comments: z.object({ comments: z.object({
server: z.string().url().readonly(), server: z.string().url().readonly(),
@ -187,9 +188,10 @@ const options: z.input<typeof Options> = {
}, },
sidebar: { sidebar: {
search: true, search: true,
post: 6, post: 5,
comment: 6, comment: 5,
tag: 20, tag: 10,
calendar: true,
}, },
comments: { comments: {
server: 'https://comment.yufan.me', server: 'https://comment.yufan.me',

View File

@ -2740,11 +2740,11 @@ a:hover .overlay {
search style search style
--------------------------------------------------------------*/ --------------------------------------------------------------*/
.widget_search label { .widget-search label {
display: block; display: block;
} }
.widget_search .search-field { .widget-search .search-field {
position: relative; position: relative;
display: block; display: block;
width: 100%; width: 100%;
@ -2772,46 +2772,46 @@ a:hover .overlay {
-webkit-box-shadow 0.15s ease-in-out; -webkit-box-shadow 0.15s ease-in-out;
} }
.widget_search .search-field:hover, .widget-search .search-field:hover,
.widget_search .search-field:focus { .widget-search .search-field:focus {
border-color: var(--border-muted); border-color: var(--border-muted);
-webkit-box-shadow: none; -webkit-box-shadow: none;
box-shadow: none; box-shadow: none;
outline: 0; outline: 0;
} }
.widget_search .screen-reader-text, .widget-search .screen-reader-text,
.widget_search .search-submit { .widget-search .search-submit {
display: none; display: none;
} }
/*-------------------------------------------------------------- /*--------------------------------------------------------------
widget_recent_comments style widget-recent-comments style
widget_recent_entries style widget-recent-entries style
--------------------------------------------------------------*/ --------------------------------------------------------------*/
.widget_recent_entries ul, .widget-recent-entries ul,
.widget_recent_comments ul { .widget-recent-comments ul {
padding-left: 1.25rem; padding-left: 1.25rem;
} }
.widget_recent_entries ul li, .widget-recent-entries ul li,
.widget_recent_comments ul li { .widget-recent-comments ul li {
margin-bottom: 0.75rem; margin-bottom: 0.75rem;
list-style-type: circle; list-style-type: circle;
font-size: inherit; font-size: inherit;
} }
.widget_recent_entries ul li a { .widget-recent-entries ul li a {
display: block; display: block;
} }
.widget_recent_entries ul li span { .widget-recent-entries ul li span {
color: var(--color-muted); color: var(--color-muted);
font-size: inherit; font-size: inherit;
} }
.widget_recent_comments ul li span { .widget-recent-comments ul li span {
font-weight: 600; font-weight: 600;
color: var(--color-dark); color: var(--color-dark);
margin-right: 5px; margin-right: 5px;
@ -2850,7 +2850,7 @@ a:hover .overlay {
} }
/*-------------------------------------------------------------- /*--------------------------------------------------------------
widget_recent_comments style widget-recent-comments style
--------------------------------------------------------------*/ --------------------------------------------------------------*/
.widget_nav_menu ul li { .widget_nav_menu ul li {

View File

@ -2,7 +2,7 @@
import options from '@/options'; import options from '@/options';
--- ---
<div id="search" class="widget widget_search" hidden={!options.settings.sidebar.search}> <div id="search" class="widget widget-search" hidden={!options.settings.sidebar.search}>
<div class="search-form"> <div class="search-form">
<label> <label>
<span class="screen-reader-text">搜索:</span> <span class="screen-reader-text">搜索:</span>

View File

@ -0,0 +1,30 @@
---
import options from '@/options';
import { DateTime } from 'luxon';
const loadCalendarImage = async (): Promise<string> => {
const now = DateTime.now().setZone(options.settings.timeZone);
const link = `https://img.owspace.com/Public/uploads/Download/${now.year}/${now.toFormat('LLdd')}.jpg`;
const response = await fetch(link, {
referrer: '',
});
if (!response.ok) {
console.error(`Failed to fetch image ${link}`);
return '';
}
const encodedImage = Buffer.from(await response.arrayBuffer()).toString('base64');
return `data:image/jpeg;base64,${encodedImage}`;
};
const calendarImage = !options.settings.sidebar.calendar ? '' : await loadCalendarImage();
---
{
calendarImage !== '' && (
<div class="widget widget-owspace-calendar">
<img src={calendarImage} />
</div>
)
}

View File

@ -14,7 +14,7 @@ const randomSize = options.settings.sidebar.post;
{ {
randomSize > 0 && ( randomSize > 0 && (
<div id="recent_posts" class="widget widget_recent_entries"> <div id="recent_posts" class="widget widget-recent-entries">
<div class="widget-title">随机文章</div> <div class="widget-title">随机文章</div>
<ul class="line"> <ul class="line">
{_.sampleSize(posts, randomSize).map((post) => ( {_.sampleSize(posts, randomSize).map((post) => (

View File

@ -12,15 +12,17 @@ const { tags } = Astro.props;
const randomSize = options.settings.sidebar.tag; const randomSize = options.settings.sidebar.tag;
--- ---
<div id="tag_cloud" class="widget widget_tag_cloud"> {
randomSize > 0 && (
<div id="tag_cloud" class="widget widget-tag-cloud">
<div class="widget-title">文章标签</div> <div class="widget-title">文章标签</div>
<div class="tagcloud"> <div class="tagcloud">
{ {_.sampleSize(tags, randomSize).map((tag) => (
_.sampleSize(tags, randomSize).map((tag) => (
<a href={tag.permalink} class="tag-cloud-link" title={`${tag.name} (${tag.counts} 篇文章)`}> <a href={tag.permalink} class="tag-cloud-link" title={`${tag.name} (${tag.counts} 篇文章)`}>
{tag.name} {tag.name}
</a> </a>
)) ))}
</div>
</div>
)
} }
</div>
</div>

View File

@ -1,17 +1,15 @@
--- ---
import { latestComments } from '@/helpers/db/query'; import { latestComments } from '@/helpers/db/query';
import options from '@/options'; import options from '@/options';
const comments = await latestComments();
--- ---
{ {
options.settings.sidebar.comment > 0 && ( options.settings.sidebar.comment > 0 && (
<div id="recent-comments" class="widget widget_recent_comments"> <div id="recent-comments" class="widget widget-recent-comments">
<div class="widget-title">近期评论</div> <div class="widget-title">近期评论</div>
<ul id="recentcomments"> <ul id="recent-comments">
{comments.map((comment) => ( {(await latestComments()).map((comment) => (
<li class="recentcomments"> <li class="recent-comments">
<span class="comment-author-link"> <span class="comment-author-link">
{comment.authorLink === '' ? ( {comment.authorLink === '' ? (
comment.author comment.author

View File

@ -1,5 +1,6 @@
--- ---
import SearchBar from '@/components/search/SearchBar.astro'; import SearchBar from '@/components/search/SearchBar.astro';
import OwspaceCalendar from '@/components/sidebar/OwspaceCalendar.astro';
import RandomPosts from '@/components/sidebar/RandomPosts.astro'; import RandomPosts from '@/components/sidebar/RandomPosts.astro';
import RandomTags from '@/components/sidebar/RandomTags.astro'; import RandomTags from '@/components/sidebar/RandomTags.astro';
import RecentComments from '@/components/sidebar/RecentComments.astro'; import RecentComments from '@/components/sidebar/RecentComments.astro';
@ -19,5 +20,6 @@ const { posts, tags } = Astro.props;
<RandomPosts {posts} /> <RandomPosts {posts} />
<RecentComments /> <RecentComments />
<RandomTags {tags} /> <RandomTags {tags} />
<OwspaceCalendar />
</div> </div>
</aside> </aside>