sitemap bugfixing
This commit is contained in:
parent
8ca1b417c4
commit
cfa298a59d
@ -19,6 +19,21 @@ type FlyAndScaleParams = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export function convertToSlug(title) {
|
||||||
|
// Remove punctuation, hyphens, and special characters
|
||||||
|
const cleanedTitle = title
|
||||||
|
.replace(/[-.,?!:"]/g, "") // Remove punctuation and hyphens
|
||||||
|
.replace(/\s+/g, " ") // Replace multiple spaces with a single space
|
||||||
|
.trim(); // Remove leading and trailing spaces
|
||||||
|
|
||||||
|
// Convert to lowercase, split by spaces, and join with hyphens
|
||||||
|
const words = cleanedTitle.toLowerCase().split(" ");
|
||||||
|
const truncatedWords = words;
|
||||||
|
|
||||||
|
// Join with hyphens
|
||||||
|
const slug = truncatedWords.join("-");
|
||||||
|
return slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function isPWAInstalled() {
|
export function isPWAInstalled() {
|
||||||
|
|||||||
@ -1,26 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { numberOfUnreadNotification } from "$lib/store";
|
import { numberOfUnreadNotification } from "$lib/store";
|
||||||
import { getImageURL } from "$lib/utils";
|
import { getImageURL, convertToSlug } from "$lib/utils";
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
let allBlogPosts = data?.getAllBlogPost;
|
let allBlogPosts = data?.getAllBlogPost;
|
||||||
|
|
||||||
function convertToSlug(title) {
|
|
||||||
// Remove punctuation and special characters
|
|
||||||
const cleanedTitle = title
|
|
||||||
.replace(/[.,?!:"]/g, "") // Remove punctuation
|
|
||||||
.replace(/\s+/g, " ") // Replace multiple spaces with a single space
|
|
||||||
.trim(); // Remove leading and trailing spaces
|
|
||||||
|
|
||||||
// Convert to lowercase, split by spaces, and join with hyphens
|
|
||||||
const words = cleanedTitle.toLowerCase().split(" ");
|
|
||||||
const truncatedWords = words;
|
|
||||||
|
|
||||||
// Join with hyphens and add ellipsis if necessary
|
|
||||||
const slug = truncatedWords.join("-");
|
|
||||||
return slug;
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
|
|||||||
@ -1,15 +1,4 @@
|
|||||||
function convertToSlug(title) {
|
import { convertToSlug } from "$lib/utils";
|
||||||
// Remove punctuation and special characters
|
|
||||||
const cleanedTitle = title
|
|
||||||
.replace(/[.,?!:"]/g, "") // Remove punctuation
|
|
||||||
.replace(/\s+/g, " ") // Replace multiple spaces with a single space
|
|
||||||
.trim(); // Remove leading and trailing spaces
|
|
||||||
|
|
||||||
// Convert to lowercase, split by spaces, and join with hyphens
|
|
||||||
const words = cleanedTitle.toLowerCase().split(" ");
|
|
||||||
const slug = words.join("-");
|
|
||||||
return slug;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const load = async ({ locals, params }) => {
|
export const load = async ({ locals, params }) => {
|
||||||
const { pb } = locals;
|
const { pb } = locals;
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import { convertToSlug } from "$lib/utils";
|
||||||
|
|
||||||
const pages = [
|
const pages = [
|
||||||
{ title: "/" },
|
{ title: "/" },
|
||||||
{ title: "/cramer-tracker" },
|
{ title: "/cramer-tracker" },
|
||||||
@ -66,13 +68,12 @@ const pages = [
|
|||||||
{ title: "/analysts/top-stocks" },
|
{ title: "/analysts/top-stocks" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const site = "https://stocknear.com";
|
|
||||||
const website = "https://stocknear.com";
|
const website = "https://stocknear.com";
|
||||||
|
|
||||||
/** @type {import('./$types').RequestHandler} */
|
/** @type {import('./$types').RequestHandler} */
|
||||||
export async function GET({ locals }) {
|
export async function GET({ locals }) {
|
||||||
//get all posts;
|
//get all posts;
|
||||||
const { apiKey, apiURL } = locals;
|
const { apiKey, apiURL, pb } = locals;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -90,7 +91,12 @@ export async function GET({ locals }) {
|
|||||||
type: item?.type,
|
type: item?.type,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const body = sitemap(stocks, pages);
|
|
||||||
|
const articles = await pb.collection("articles").getFullList({
|
||||||
|
sort: "-created",
|
||||||
|
});
|
||||||
|
|
||||||
|
const body = sitemap(stocks, articles, pages);
|
||||||
const response = new Response(body);
|
const response = new Response(body);
|
||||||
response.headers.set("Cache-Control", "max-age=0, s-maxage=3600");
|
response.headers.set("Cache-Control", "max-age=0, s-maxage=3600");
|
||||||
response.headers.set("Content-Type", "application/xml");
|
response.headers.set("Content-Type", "application/xml");
|
||||||
@ -100,6 +106,7 @@ export async function GET({ locals }) {
|
|||||||
// Modified sitemap function
|
// Modified sitemap function
|
||||||
const sitemap = (
|
const sitemap = (
|
||||||
stocks,
|
stocks,
|
||||||
|
articles,
|
||||||
pages,
|
pages,
|
||||||
) => `<?xml version="1.0" encoding="UTF-8" ?>
|
) => `<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<urlset
|
<urlset
|
||||||
@ -116,6 +123,15 @@ const sitemap = (
|
|||||||
<url>
|
<url>
|
||||||
<loc>${website}${page.title}</loc>
|
<loc>${website}${page.title}</loc>
|
||||||
</url>
|
</url>
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.join("")}
|
||||||
|
${articles
|
||||||
|
.map(
|
||||||
|
(item) => `
|
||||||
|
<url>
|
||||||
|
<loc>${website}/blog/${convertToSlug(item?.title)}</loc>
|
||||||
|
</url>
|
||||||
`,
|
`,
|
||||||
)
|
)
|
||||||
.join("")}
|
.join("")}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user