It seems that next-sitemap is unable to produce sitemaps for dynamic paths, so we're switching back to dynamic server-side sitemap generation
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -34,4 +34,6 @@ yarn-error.log*
|
|||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
next-env.d.ts
|
next-env.d.ts
|
||||||
|
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
public/sitemap.xml
|
||||||
12
next-sitemap.config.js
Normal file
12
next-sitemap.config.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
/* 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}`)
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
|
"postbuild": "next-sitemap",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
},
|
},
|
||||||
@@ -24,6 +25,7 @@
|
|||||||
"jsdom": "^22.1.0",
|
"jsdom": "^22.1.0",
|
||||||
"lucide-react": "^0.279.0",
|
"lucide-react": "^0.279.0",
|
||||||
"next": "latest",
|
"next": "latest",
|
||||||
|
"next-sitemap": "^4.2.3",
|
||||||
"next-themes": "^0.2.1",
|
"next-themes": "^0.2.1",
|
||||||
"node-html-parser": "^6.1.10",
|
"node-html-parser": "^6.1.10",
|
||||||
"node-telegram-bot-api": "^0.63.0",
|
"node-telegram-bot-api": "^0.63.0",
|
||||||
|
|||||||
21
pnpm-lock.yaml
generated
21
pnpm-lock.yaml
generated
@@ -50,6 +50,9 @@ dependencies:
|
|||||||
next:
|
next:
|
||||||
specifier: latest
|
specifier: latest
|
||||||
version: 13.5.3(react-dom@18.2.0)(react@18.2.0)
|
version: 13.5.3(react-dom@18.2.0)(react@18.2.0)
|
||||||
|
next-sitemap:
|
||||||
|
specifier: ^4.2.3
|
||||||
|
version: 4.2.3(next@13.5.3)
|
||||||
next-themes:
|
next-themes:
|
||||||
specifier: ^0.2.1
|
specifier: ^0.2.1
|
||||||
version: 0.2.1(next@13.5.3)(react-dom@18.2.0)(react@18.2.0)
|
version: 0.2.1(next@13.5.3)(react-dom@18.2.0)(react@18.2.0)
|
||||||
@@ -136,6 +139,10 @@ packages:
|
|||||||
dependencies:
|
dependencies:
|
||||||
regenerator-runtime: 0.14.0
|
regenerator-runtime: 0.14.0
|
||||||
|
|
||||||
|
/@corex/deepmerge@4.0.43:
|
||||||
|
resolution: {integrity: sha512-N8uEMrMPL0cu/bdboEWpQYb/0i2K5Qn8eCsxzOmxSggJbbQte7ljMRoXm917AbntqTGOzdTu+vP3KOOzoC70HQ==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/@eslint-community/eslint-utils@4.4.0(eslint@8.50.0):
|
/@eslint-community/eslint-utils@4.4.0(eslint@8.50.0):
|
||||||
resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==}
|
resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==}
|
||||||
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
|
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
|
||||||
@@ -3063,6 +3070,20 @@ packages:
|
|||||||
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
|
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/next-sitemap@4.2.3(next@13.5.3):
|
||||||
|
resolution: {integrity: sha512-vjdCxeDuWDzldhCnyFCQipw5bfpl4HmZA7uoo3GAaYGjGgfL4Cxb1CiztPuWGmS+auYs7/8OekRS8C2cjdAsjQ==}
|
||||||
|
engines: {node: '>=14.18'}
|
||||||
|
hasBin: true
|
||||||
|
peerDependencies:
|
||||||
|
next: '*'
|
||||||
|
dependencies:
|
||||||
|
'@corex/deepmerge': 4.0.43
|
||||||
|
'@next/env': 13.5.3
|
||||||
|
fast-glob: 3.3.1
|
||||||
|
minimist: 1.2.8
|
||||||
|
next: 13.5.3(react-dom@18.2.0)(react@18.2.0)
|
||||||
|
dev: false
|
||||||
|
|
||||||
/next-themes@0.2.1(next@13.5.3)(react-dom@18.2.0)(react@18.2.0):
|
/next-themes@0.2.1(next@13.5.3)(react-dom@18.2.0)(react@18.2.0):
|
||||||
resolution: {integrity: sha512-B+AKNfYNIzh0vqQQKqQItTS8evEouKD7H5Hj3kmuPERwddR2TxvDSFZuTj6T7Jfn1oyeUyJMydPl1Bkxkh0W7A==}
|
resolution: {integrity: sha512-B+AKNfYNIzh0vqQQKqQItTS8evEouKD7H5Hj3kmuPERwddR2TxvDSFZuTj6T7Jfn1oyeUyJMydPl1Bkxkh0W7A==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { getSchedule } from '@/app/agregator/schedule'
|
|||||||
import { NextSerialized, nextDeserializer, nextSerialized } from '@/app/utils/date-serializer'
|
import { NextSerialized, nextDeserializer, nextSerialized } from '@/app/utils/date-serializer'
|
||||||
import { NavBar } from '@/widgets/navbar'
|
import { NavBar } from '@/widgets/navbar'
|
||||||
import { LastUpdateAt } from '@/entities/last-update-at'
|
import { LastUpdateAt } from '@/entities/last-update-at'
|
||||||
import { groups } from '@/shared/data/groups'
|
import groups from '@/shared/data/groups.json'
|
||||||
import crypto from 'crypto'
|
import crypto from 'crypto'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { getDayOfWeek } from '@/shared/utils'
|
import { getDayOfWeek } from '@/shared/utils'
|
||||||
@@ -61,6 +61,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext<{ gr
|
|||||||
if (group && Object.hasOwn(groups, group) && group in groups) {
|
if (group && Object.hasOwn(groups, group) && group in groups) {
|
||||||
let schedule
|
let schedule
|
||||||
let parsedAt
|
let parsedAt
|
||||||
|
const groupName = group as keyof typeof groups
|
||||||
|
|
||||||
const cachedSchedule = cachedSchedules.get(group)
|
const cachedSchedule = cachedSchedules.get(group)
|
||||||
if (cachedSchedule?.lastFetched && Date.now() - cachedSchedule.lastFetched.getTime() < maxCacheDurationInMS) {
|
if (cachedSchedule?.lastFetched && Date.now() - cachedSchedule.lastFetched.getTime() < maxCacheDurationInMS) {
|
||||||
@@ -68,9 +69,10 @@ export async function getServerSideProps(context: GetServerSidePropsContext<{ gr
|
|||||||
parsedAt = cachedSchedule.lastFetched
|
parsedAt = cachedSchedule.lastFetched
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
schedule = await getSchedule(...groups[group])
|
const group = groups[groupName] as [number, string]
|
||||||
|
schedule = await getSchedule(...group)
|
||||||
parsedAt = new Date()
|
parsedAt = new Date()
|
||||||
cachedSchedules.set(group, { lastFetched: new Date(), results: schedule })
|
cachedSchedules.set(groupName, { lastFetched: new Date(), results: schedule })
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
if (cachedSchedule?.lastFetched) {
|
if (cachedSchedule?.lastFetched) {
|
||||||
schedule = cachedSchedule.results
|
schedule = cachedSchedule.results
|
||||||
@@ -103,7 +105,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext<{ gr
|
|||||||
props: nextSerialized({
|
props: nextSerialized({
|
||||||
schedule: schedule,
|
schedule: schedule,
|
||||||
parsedAt: parsedAt,
|
parsedAt: parsedAt,
|
||||||
group: groups[group][1]
|
group: groups[groupName][1]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
4
src/shared/data/groups.json
Normal file
4
src/shared/data/groups.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"ps7": [146, "ПС-7"],
|
||||||
|
"pks35k": [78, "ПКС-35к"]
|
||||||
|
}
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
export const groups: { [group: string]: [number, string] } = {
|
|
||||||
ps7: [146, 'ПС-7'],
|
|
||||||
pks35k: [78, 'ПКС-35к']
|
|
||||||
}
|
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
"**/*.ts",
|
"**/*.ts",
|
||||||
"**/*.tsx",
|
"**/*.tsx",
|
||||||
".next/types/**/*.ts"
|
".next/types/**/*.ts"
|
||||||
],
|
, "next-sitemap.config.js" ],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules"
|
"node_modules"
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user