diff --git a/.gitignore b/.gitignore index 531e5f0..62190d7 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,4 @@ yarn-error.log* *.tsbuildinfo next-env.d.ts -.env - -public/sitemap.xml \ No newline at end of file +.env \ No newline at end of file diff --git a/.npmrc b/.npmrc deleted file mode 100644 index b7425b9..0000000 --- a/.npmrc +++ /dev/null @@ -1 +0,0 @@ -enable-pre-post-scripts=true \ No newline at end of file diff --git a/next-sitemap.config.js b/next-sitemap.config.js deleted file mode 100644 index 1231607..0000000 --- a/next-sitemap.config.js +++ /dev/null @@ -1,12 +0,0 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ -const groups = require('./src/shared/data/groups.json') - -/** @type {import('next-sitemap').IConfig} */ -module.exports = { - siteUrl: 'https://kspsuti.ru', - generateRobotsTxt: false, - generateIndexSitemap: false, - changefreq: 'weekly', - exclude: ['/'], - additionalPaths: async () => Object.keys(groups).map(groupName => `/${groupName}`) -} \ No newline at end of file diff --git a/package.json b/package.json index d490470..de6687b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,6 @@ "scripts": { "dev": "next dev", "build": "next build", - "postbuild": "next-sitemap", "start": "next start", "lint": "next lint" }, diff --git a/public/robots.txt b/public/robots.txt index 6f27bb6..288c1d3 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1,2 +1,4 @@ User-agent: * -Disallow: \ No newline at end of file +Disallow: + +Sitemap: https://kspsuti.ru/sitemap.xml \ No newline at end of file diff --git a/src/pages/[group].tsx b/src/pages/[group].tsx index 14d863d..77f0b9b 100644 --- a/src/pages/[group].tsx +++ b/src/pages/[group].tsx @@ -5,7 +5,7 @@ import { getSchedule } from '@/app/agregator/schedule' import { NextSerialized, nextDeserializer, nextSerialized } from '@/app/utils/date-serializer' import { NavBar } from '@/widgets/navbar' import { LastUpdateAt } from '@/entities/last-update-at' -import groups from '@/shared/data/groups.json' +import { groups } from '@/shared/data/groups' import crypto from 'crypto' import React from 'react' import { getDayOfWeek } from '@/shared/utils' @@ -61,7 +61,6 @@ export async function getServerSideProps(context: GetServerSidePropsContext<{ gr if (group && Object.hasOwn(groups, group) && group in groups) { let schedule let parsedAt - const groupName = group as keyof typeof groups const cachedSchedule = cachedSchedules.get(group) if (cachedSchedule?.lastFetched && Date.now() - cachedSchedule.lastFetched.getTime() < maxCacheDurationInMS) { @@ -69,10 +68,9 @@ export async function getServerSideProps(context: GetServerSidePropsContext<{ gr parsedAt = cachedSchedule.lastFetched } else { try { - const group = groups[groupName] as [number, string] - schedule = await getSchedule(...group) + schedule = await getSchedule(...groups[group]) parsedAt = new Date() - cachedSchedules.set(groupName, { lastFetched: new Date(), results: schedule }) + cachedSchedules.set(group, { lastFetched: new Date(), results: schedule }) } catch(e) { if (cachedSchedule?.lastFetched) { schedule = cachedSchedule.results @@ -105,7 +103,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext<{ gr props: nextSerialized({ schedule: schedule, parsedAt: parsedAt, - group: groups[groupName][1] + group: groups[group][1] }) } } else { diff --git a/src/pages/sitemap.xml/index.tsx b/src/pages/sitemap.xml/index.tsx new file mode 100644 index 0000000..f6431e2 --- /dev/null +++ b/src/pages/sitemap.xml/index.tsx @@ -0,0 +1,19 @@ +import { ISitemapField, getServerSideSitemapLegacy } from 'next-sitemap' +import { GetServerSideProps } from 'next' +import { groups } from '@/shared/data/groups' + +export const getServerSideProps: GetServerSideProps = async (ctx) => { + const siteURL = 'https://kspsuti.ru' + + const fields = Object.keys(groups).map(group => ( + { + loc: `${siteURL}/${group}`, + changefreq: 'weekly', + priority: 0.8 + } + )) + + return getServerSideSitemapLegacy(ctx, fields) +} + +export default function Sitemap() { } \ No newline at end of file diff --git a/src/shared/data/groups.json b/src/shared/data/groups.json deleted file mode 100644 index 19ec471..0000000 --- a/src/shared/data/groups.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "ps7": [146, "ПС-7"], - "pks35k": [78, "ПКС-35к"] -} \ No newline at end of file diff --git a/src/shared/data/groups.ts b/src/shared/data/groups.ts new file mode 100644 index 0000000..55a688a --- /dev/null +++ b/src/shared/data/groups.ts @@ -0,0 +1,4 @@ +export const groups: { [group: string]: [number, string] } = { + ps7: [146, 'ПС-7'], + pks35k: [78, 'ПКС-35к'] +} \ No newline at end of file