Skip to content

Commit

Permalink
update: sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
521xueweihan committed Aug 16, 2024
1 parent 4d90f3b commit 39563d1
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 27 deletions.
4 changes: 1 addition & 3 deletions src/components/periodical/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ const PeriodItem: NextPage<PeriodicalItemProps> = ({ item, index }) => {
{/* markdown 内容渲染 */}
<MDRender className='markdown-body'>
{i18n.language == 'en'
? item.description_en
? item.description_en
: item.description
? item.description_en || item.description
: item.description}
</MDRender>
{/* 图片预览 */}
Expand Down
2 changes: 1 addition & 1 deletion src/components/respository/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ const Info = ({ repo, t, i18n_lang }: RepositoryProps) => {
</div>
<div className='flex flex-1 flex-row flex-wrap justify-between'>
<div className='mb-2 flex w-full flex-col gap-y-2 md:hidden'>
<div className='flex flex-row items-center '>
<div className='flex flex-row items-center'>
<CustomLink
href={repo.url}
onClick={() => handleClickLink('source', repo.rid)}
Expand Down
4 changes: 3 additions & 1 deletion src/components/respository/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ const Tabs = ({ repo, t, i18n_lang }: RepositoryProps) => {
>
<a>
<div className='mb-1 mr-1 flex h-5 cursor-pointer items-center rounded-xl bg-blue-100 px-2.5 text-xs text-blue-500 hover:bg-blue-200 dark:bg-blue-500 dark:text-gray-100 dark:hover:bg-blue-700 lg:mr-2'>
{item.name}
{i18n_lang == 'en'
? item.name_en || item.name
: item.name}
</div>
</a>
</Link>
Expand Down
9 changes: 6 additions & 3 deletions src/components/side/UserStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,21 @@ export default function UserStatus({ t }: SideProps) {
<div className='flex-grow' />
<div className='justify-end'>
<div
className='flex flex-row items-center'
className='flex cursor-pointer flex-row'
onClick={() => {
router.push('/notification');
}}
>
<span className='relative inline-flex cursor-pointer'>
<span className='relative inline-block'>
<AiOutlineBell
size={20}
className='text-gray-500 hover:text-blue-500 dark:text-gray-400 dark:hover:text-blue-500'
/>
{userInfo?.unread.total > 0 && (
<span className='relative right-1 inline-flex h-1.5 w-1.5 rounded-full bg-red-500' />
<span className='absolute top-0.5 right-0 flex h-1.5 w-1.5 translate-x-1/2 -translate-y-1/2'>
<span className='absolute inline-flex h-full w-full animate-ping rounded-full bg-blue-400 opacity-75' />
<span className='relative inline-flex h-1.5 w-1.5 rounded-full bg-blue-500' />
</span>
)}
</span>
</div>
Expand Down
12 changes: 7 additions & 5 deletions src/pages/server-sitemap-index.xml/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
import { GetServerSideProps, GetServerSidePropsContext } from 'next';
import { getServerSideSitemap, ISitemapField } from 'next-sitemap';

import { getURLs } from '@/services/sitemap';
import { getSitemap } from '@/services/home';

export const getServerSideProps: GetServerSideProps = async (
ctx: GetServerSidePropsContext
) => {
// Method to source urls from cms
const data = await getURLs();
const allURLs = data?.data.map((url) => {
const data = await getSitemap();
const allURLs = data?.data.map((item) => {
return {
loc: url,
changefreq: 'weekly',
loc: item.loc,
lastmod: item.lastmod,
priority: item.priority,
changefreq: item.changefreq,
} as ISitemapField;
});
return getServerSideSitemap(ctx, allURLs);
Expand Down
13 changes: 12 additions & 1 deletion src/services/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { makeUrl } from '@/utils/api';

import { fetcher } from './base';

import { HomeItem, HomeItems, RecommendItems, Stats } from '@/types/home';
import {
HomeItem,
HomeItems,
RecommendItems,
Sitemap,
Stats,
} from '@/types/home';
import { TagItems } from '@/types/tag';

export const getItems = async (
Expand Down Expand Up @@ -87,3 +93,8 @@ export const createFeedback = async (data: {
};
export type HomeItemData = HomeItem[];
export const DataContext = createContext<HomeItemData>([]);

export const getSitemap = async (): Promise<Sitemap> => {
const data = await fetcher<Sitemap>(makeUrl(`/sitemap/`));
return data;
};
13 changes: 0 additions & 13 deletions src/services/sitemap.ts

This file was deleted.

12 changes: 12 additions & 0 deletions src/types/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,15 @@ export interface CreateFeedbackRes {
message: string;
success: boolean;
}

export interface SitemapItem {
loc: string;
lastmod?: string;
changefreq?: string;
priority?: number;
}

export interface Sitemap {
success: boolean;
data: SitemapItem[];
}
1 change: 1 addition & 0 deletions src/types/tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface SelectTagItems {

export interface TagType {
name: string;
name_en: string;
tid: string;
}

Expand Down

0 comments on commit 39563d1

Please sign in to comment.