Add hashtag cascade relations

This commit is contained in:
LeonspaceX
2026-01-31 17:11:08 +08:00
parent 8e561a2eb7
commit 3a30271fe6
3 changed files with 63 additions and 17 deletions

View File

@@ -261,10 +261,14 @@ useEffect(() => {
const diffHours = Math.floor(diffMs / 3600000);
const sameDay = now.toDateString() === date.toDateString();
if (sameDay) return `${diffHours}小时前`;
const diffDays = Math.floor(diffMs / 86400000);
const diffMonths = Math.floor(diffDays / 30);
if (diffMonths >= 1 && diffMonths < 12) return `${diffMonths}个月前`;
if (diffDays >= 1 && diffMonths < 1) return `${diffDays}天前`;
const todayMidnight = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
const dateMidnight = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
const diffDays = Math.max(1, Math.floor((todayMidnight - dateMidnight) / 86400000));
if (diffDays < 30) return `${diffDays}天前`;
let diffMonths = (now.getFullYear() * 12 + now.getMonth()) - (date.getFullYear() * 12 + date.getMonth());
if (now.getDate() < date.getDate()) diffMonths -= 1;
if (diffMonths < 1) diffMonths = 1;
if (diffMonths < 12) return `${diffMonths}个月前`;
const yyyy = date.getFullYear();
const mm = String(date.getMonth() + 1).padStart(2, '0');
const dd = String(date.getDate()).padStart(2, '0');
@@ -293,13 +297,12 @@ useEffect(() => {
a: ({ node, ...props }) => {
const href = props.href;
if (href && typeof href === 'string' && href.startsWith('/tag/#')) {
const hash = href.slice('/tag/'.length);
return (
<a
{...props}
onClick={(e) => {
e.preventDefault();
navigate({ pathname: '/tag', hash });
navigate(href);
}}
/>
);

View File

@@ -252,10 +252,14 @@ const PostCard = ({
const diffHours = Math.floor(diffMs / 3600000);
const sameDay = now.toDateString() === date.toDateString();
if (sameDay) return `${diffHours}小时前`;
const diffDays = Math.floor(diffMs / 86400000);
const diffMonths = Math.floor(diffDays / 30);
if (diffMonths >= 1 && diffMonths < 12) return `${diffMonths}个月前`;
if (diffDays >= 1 && diffMonths < 1) return `${diffDays}天前`;
const todayMidnight = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
const dateMidnight = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
const diffDays = Math.max(1, Math.floor((todayMidnight - dateMidnight) / 86400000));
if (diffDays < 30) return `${diffDays}天前`;
let diffMonths = (now.getFullYear() * 12 + now.getMonth()) - (date.getFullYear() * 12 + date.getMonth());
if (now.getDate() < date.getDate()) diffMonths -= 1;
if (diffMonths < 1) diffMonths = 1;
if (diffMonths < 12) return `${diffMonths}个月前`;
const yyyy = date.getFullYear();
const mm = String(date.getMonth() + 1).padStart(2, '0');
const dd = String(date.getDate()).padStart(2, '0');
@@ -275,13 +279,12 @@ const PostCard = ({
a: ({ node, ...props }) => {
const href = props.href;
if (href && typeof href === 'string' && href.startsWith('/tag/#')) {
const hash = href.slice('/tag/'.length);
return (
<a
{...props}
onClick={(e) => {
e.preventDefault();
navigate({ pathname: '/tag', hash });
navigate(href);
}}
/>
);