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(
|
||||
method: string,
|
||||
resource: string,
|
||||
queryParams: Record<string, string>,
|
||||
data?: Record<string, unknown>
|
||||
queryParams: Record<string, string>
|
||||
) {
|
||||
let perPage = Number(queryParams?.limit);
|
||||
if (perPage > 30) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
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';
|
||||
|
||||
export async function GET({ setHeaders, url }) {
|
||||
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;
|
||||
if (Number(limit) > 30) {
|
||||
limit = PAGE_SIZE;
|
||||
|
|
|
|||
|
|
@ -5,11 +5,6 @@ import type { ArticlePageLoad } from '$lib/types/article';
|
|||
|
||||
export const load: PageServerLoad = async ({ fetch, params, setHeaders, url }) => {
|
||||
const { page } = params;
|
||||
// if (+page > +WALLABAG_MAX_PAGES) {
|
||||
// error(404, {
|
||||
// message: 'Not found',
|
||||
// });
|
||||
// }
|
||||
const resp = await fetch(`/api/articles?page=${page}`);
|
||||
const {
|
||||
articles,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
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}`;
|
||||
|
||||
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" ?>
|
||||
<urlset
|
||||
xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"
|
||||
|
|
@ -32,7 +35,7 @@ export const GET: RequestHandler = async function GET({ setHeaders }) {
|
|||
<priority>1</priority>
|
||||
</url>
|
||||
|
||||
${Array.from({ length: parseInt(WALLABAG_MAX_PAGES) }, (_, i) => {
|
||||
${Array.from({ length: totalPages }, (_, i) => {
|
||||
return `
|
||||
<url>
|
||||
<loc>${site}/articles/${i + 1}</loc>
|
||||
|
|
|
|||
Loading…
Reference in a new issue