-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jiaziling
committed
Sep 12, 2024
1 parent
ce37a6f
commit 51c4783
Showing
19 changed files
with
941 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--- | ||
import CommentAside from './CommentAside.astro' | ||
import { comment } from '../consts' | ||
import { getCollectionByName } from '../utils/getCollectionByName' | ||
import getUniqueTags from '../utils/getUniqueTags' | ||
import getCountByCategory from '../utils/getCountByCategory' | ||
import { sortPostsByDate } from '../utils/sortPostsByDate' | ||
import { site } from '../consts' | ||
import { t } from '../i18n/utils' | ||
const blogs = await getCollectionByName('blog') | ||
let tagArr = getUniqueTags(blogs) | ||
let categoryCount = getCountByCategory(blogs) | ||
let sortPosts = await sortPostsByDate(blogs) | ||
let resultPosts = sortPosts.splice(0, site.recentBlogSize) | ||
--- | ||
|
||
<div> | ||
{ | ||
Object.keys(categoryCount).length > 0 && ( | ||
<div class="aside-widget"> | ||
<i class="ri-folder-line menu-icon" /> | ||
{t('sidebar.categories')} | ||
</div> | ||
) | ||
} | ||
{ | ||
Object.keys(categoryCount).map((category) => ( | ||
<a | ||
class="my-1 truncate block hover:text-skin-active" | ||
title={category + ' (' + categoryCount[category] + ')'} | ||
href={'/category/' + category} | ||
> | ||
{(category === 'uncategorized' ? t('sidebar.uncategorized') : category) + ' (' + categoryCount[category] + ')'} | ||
</a> | ||
)) | ||
} | ||
</div> | ||
<div> | ||
{ | ||
tagArr.length > 0 && ( | ||
<div class="aside-widget"> | ||
<i class="ri-price-tag-3-line menu-icon" /> | ||
{t('sidebar.tags')} | ||
</div> | ||
) | ||
} | ||
<div class="flex flex-wrap"> | ||
{ | ||
tagArr && | ||
tagArr.map((tag: any) => ( | ||
<a | ||
class="inline-block truncate m-1 border p-1 text-sm rounded hover:text-skin-active" | ||
title={tag} | ||
href={'/tags/' + tag} | ||
> | ||
{tag} | ||
</a> | ||
)) | ||
} | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<div class="aside-widget"> | ||
<i class="ri-file-line menu-icon"></i> | ||
{t('sidebar.recentArticle')} | ||
</div> | ||
<div class="flex flex-col"> | ||
{ | ||
resultPosts.map((post: any) => ( | ||
<a | ||
href={'/blog/' + post.slug} | ||
class="truncate cursor-pointr mt-1 hover:text-skin-active" | ||
title={post.data.title} | ||
> | ||
{post.data.title} | ||
</a> | ||
)) | ||
} | ||
</div> | ||
</div> | ||
|
||
{comment.enable && comment.type === 'waline' && <CommentAside />} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
import { comment } from '../consts' | ||
import { t } from '../i18n/utils' | ||
--- | ||
|
||
{ | ||
comment.enable && comment.type === 'waline' && ( | ||
<div> | ||
<div class="aside-widget"> | ||
<i class="ri-chat-1-line menu-icon" /> | ||
{t('sidebar.recentComments')} | ||
</div> | ||
<div id="waline-comment" /> | ||
</div> | ||
) | ||
} | ||
|
||
<script> | ||
import { comment } from '../consts' | ||
import { formatDate } from '../utils/formatDate' | ||
|
||
const commentDiv = document.getElementById('waline-comment') | ||
if (comment.enable && comment.type === 'waline' && commentDiv) { | ||
const recentCommentUrl = `${comment.walineConfig.serverUrl}/api/comment?type=recent&count=${comment.walineConfig.count}` | ||
fetch(recentCommentUrl) | ||
.then((comment) => { | ||
return comment.json() | ||
}) | ||
.then((recentComments) => { | ||
let comments = '<ul>' | ||
recentComments.data.forEach((comment: any, index: number) => { | ||
comments += `<li>${index + 1}、${formatDate(comment.time)}` | ||
comments += `<div class="waline-comment-content"><a class="block" href="${window.location.origin + comment.url}">${comment.comment}</a></div>` | ||
comments += `<div class="waline-comment-author ">--${comment.nick}</div></li>` | ||
}) | ||
comments += '</ul>' | ||
const commentDiv = document.getElementById('waline-comment') | ||
if (!commentDiv) { | ||
return | ||
} | ||
commentDiv.innerHTML = comments | ||
}) | ||
} | ||
</script> |
Oops, something went wrong.