Skip to content

Commit

Permalink
fix: 404, 500 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
521xueweihan committed Aug 20, 2024
1 parent 36786a1 commit c30fa4c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 21 deletions.
8 changes: 7 additions & 1 deletion next-sitemap.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ module.exports = {
changefreq: 'daily',
priority: 0.7,
generateRobotsTxt: true,
exclude: ['/tachi', '/help', '/search'],
exclude: [
'/tachi',
'/user/login',
'/help',
'*/search*',
'*/periodical/statistics/click*',
],

robotsTxtOptions: {
additionalSitemaps: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build:dep": "cross-env ANALYZE=true next build",
"start": "next start",
"server_start": "pm2 start ecosystem.config.js",
"server_reload": "next-sitemap --config next-sitemap.config.js && next build && pm2 reload ecosystem.config.js",
"server_reload": "next build && next-sitemap --config next-sitemap.config.js && pm2 reload ecosystem.config.js",
"server_stop": "pm2 stop ecosystem.config.js",
"lint": "next lint",
"lint:fix": "eslint src --fix && yarn format",
Expand Down
6 changes: 4 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ const handleRedirect = (req, res, locale, urlLocale) => {
}
if (locale === DEFAULT_LOCALE) {
const newUrl = req.url.replace(`/${DEFAULT_LOCALE}`, '') || '/';
return res.redirect(307, newUrl);
res.redirect(307, newUrl);
return true;
}
} else if (locale !== DEFAULT_LOCALE) {
let newUrl = `/${locale}${req.url}`;
if (newUrl.endsWith('/') && newUrl.length > 1) {
newUrl = newUrl.slice(0, -1);
}
return res.redirect(307, newUrl);
res.redirect(307, newUrl);
return true;
}
return false;
};
Expand Down
15 changes: 7 additions & 8 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ import IndexBar from '@/components/navbar/IndexBar';
import Seo from '@/components/Seo';
import ToTop from '@/components/toTop/ToTop';

const validSortBy = ['featured', 'all'];

const Index: NextPage = () => {
const { t, i18n } = useTranslation('home');
const router = useRouter();
const { sort_by = 'featured', tid = '' } = router.query;
const { sort_by = 'featured', tid = '' }: { sort_by?: string; tid?: string } =
router.query;
const sortBy = validSortBy.includes(sort_by) ? sort_by : 'featured';

const { isLogin } = useLoginContext();
const { repositories, isValidating, hasMore, size, sentryRef } =
useRepositories(sort_by as string, tid as string);
useRepositories(sortBy, tid);

const handleItemBottom = () => {
if (!isValidating && !hasMore) {
Expand All @@ -37,12 +41,7 @@ const Index: NextPage = () => {
return (
<>
<Seo title={t('title')} description={t('description')} />
<IndexBar
tid={tid as string}
sort_by={sort_by as string}
t={t}
i18n_lang={i18n.language}
/>
<IndexBar tid={tid} sort_by={sortBy} t={t} i18n_lang={i18n.language} />
<div className='h-screen'>
<Items repositories={repositories} i18n_lang={i18n.language} />
<div
Expand Down
27 changes: 18 additions & 9 deletions src/pages/tags/[tid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,24 @@ export const getServerSideProps: GetServerSideProps = async ({
const ip = getClientIP(req);
const tid = query?.tid as string;
const data = await getTagPageItems(ip, tid);
const tag_name =
locale == 'en' && data.tag_name_en ? data.tag_name_en : data.tag_name;
return {
props: {
...(await serverSideTranslations(locale as string, ['common', 'topic'])),
items: data.data,
tag_name: tag_name,
},
};
if (data.success) {
const tag_name =
locale == 'en' && data.tag_name_en ? data.tag_name_en : data.tag_name;
return {
props: {
...(await serverSideTranslations(locale as string, [
'common',
'topic',
])),
items: data.data,
tag_name: tag_name,
},
};
} else {
return {
notFound: true,
};
}
};

export default TagPage;
1 change: 1 addition & 0 deletions src/types/tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface TagPageProps {
}

export interface TagPage {
success: boolean;
page: number;
data: HomeItem[];
tid: string;
Expand Down

0 comments on commit c30fa4c

Please sign in to comment.