mirror of
https://github.com/BradNut/personal-website-sveltekit
synced 2025-09-08 23:20:18 +00:00
Updating sitemap.
This commit is contained in:
parent
10f79af739
commit
ec57d221f4
4 changed files with 7 additions and 13 deletions
|
|
@ -19,8 +19,7 @@ const base: string = WALLABAG_URL;
|
||||||
export async function fetchArticlesApi(
|
export async function fetchArticlesApi(
|
||||||
method: string,
|
method: string,
|
||||||
resource: string,
|
resource: string,
|
||||||
queryParams: Record<string, string>,
|
queryParams: Record<string, string>
|
||||||
data?: Record<string, unknown>
|
|
||||||
) {
|
) {
|
||||||
let perPage = Number(queryParams?.limit);
|
let perPage = Number(queryParams?.limit);
|
||||||
if (perPage > 30) {
|
if (perPage > 30) {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,9 @@
|
||||||
import { json, error } from '@sveltejs/kit';
|
import { json, error } from '@sveltejs/kit';
|
||||||
import { PAGE_SIZE, WALLABAG_MAX_PAGES } from '$env/static/private';
|
import { PAGE_SIZE } from '$env/static/private';
|
||||||
import { fetchArticlesApi } from '$lib/api';
|
import { fetchArticlesApi } from '$lib/api';
|
||||||
|
|
||||||
export async function GET({ setHeaders, url }) {
|
export async function GET({ setHeaders, url }) {
|
||||||
const page = url?.searchParams?.get('page') || '1';
|
const page = url?.searchParams?.get('page') || '1';
|
||||||
// if (+page > +WALLABAG_MAX_PAGES) {
|
|
||||||
// error(404, 'Page does not exist');
|
|
||||||
// }
|
|
||||||
let limit = url?.searchParams?.get('limit') ?? PAGE_SIZE;
|
let limit = url?.searchParams?.get('limit') ?? PAGE_SIZE;
|
||||||
if (Number(limit) > 30) {
|
if (Number(limit) > 30) {
|
||||||
limit = PAGE_SIZE;
|
limit = PAGE_SIZE;
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,6 @@ import type { ArticlePageLoad } from '$lib/types/article';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ fetch, params, setHeaders, url }) => {
|
export const load: PageServerLoad = async ({ fetch, params, setHeaders, url }) => {
|
||||||
const { page } = params;
|
const { page } = params;
|
||||||
// if (+page > +WALLABAG_MAX_PAGES) {
|
|
||||||
// error(404, {
|
|
||||||
// message: 'Not found',
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
const resp = await fetch(`/api/articles?page=${page}`);
|
const resp = await fetch(`/api/articles?page=${page}`);
|
||||||
const {
|
const {
|
||||||
articles,
|
articles,
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
import type { RequestHandler } from '@sveltejs/kit';
|
import type { RequestHandler } from '@sveltejs/kit';
|
||||||
import { PUBLIC_URL } from '$env/static/public';
|
import { PUBLIC_URL } from '$env/static/public';
|
||||||
import { WALLABAG_MAX_PAGES } from '$env/static/private';
|
import type { ArticlePageLoad } from '$lib/types/article';
|
||||||
|
|
||||||
const site = `https://${PUBLIC_URL}`;
|
const site = `https://${PUBLIC_URL}`;
|
||||||
|
|
||||||
export const GET: RequestHandler = async function GET({ setHeaders }) {
|
export const GET: RequestHandler = async function GET({ setHeaders }) {
|
||||||
|
const resp = await fetch(`/api/articles`);
|
||||||
|
const { totalPages }: ArticlePageLoad = await resp.json();
|
||||||
|
|
||||||
const xml = `<?xml version="1.0" encoding="UTF-8" ?>
|
const xml = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<urlset
|
<urlset
|
||||||
xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"
|
xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"
|
||||||
|
|
@ -32,7 +35,7 @@ export const GET: RequestHandler = async function GET({ setHeaders }) {
|
||||||
<priority>1</priority>
|
<priority>1</priority>
|
||||||
</url>
|
</url>
|
||||||
|
|
||||||
${Array.from({ length: parseInt(WALLABAG_MAX_PAGES) }, (_, i) => {
|
${Array.from({ length: totalPages }, (_, i) => {
|
||||||
return `
|
return `
|
||||||
<url>
|
<url>
|
||||||
<loc>${site}/articles/${i + 1}</loc>
|
<loc>${site}/articles/${i + 1}</loc>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue