matfantinel / sveltekit-static-blog-template

A lightweight and customizable template for blogs and portfolio websites, built with SvelteKit.
https://sveltekit-static-blog-template.vercel.app
GNU General Public License v3.0
136 stars 28 forks source link

Canonical Urls and others contain // #14

Open MarcoPeretti opened 1 month ago

MarcoPeretti commented 1 month ago

Hello there,

first of all, thank you for the template! it's great a very easy to use.

AHREF reports "Canonical URL has no incoming internal links" as the canonical ulr reported has a //.

I traced it back to the definition of siteBaseUrl which contains a trailing slash which affects og:image, twitter:image and the canonical url.

I fixed it by

  1. referring to images/abc instead /images/abc in blog posts
  2. removed the extra / in the canonical definition routes/(blog-article)/+layout.svelte)
matfantinel commented 1 month ago

Hey @MarcoPeretti , thanks for the issue report!

The steps you took make perfect sense. I am unable to do those tweaks right now, but feel free to open a pull request if you want! Otherwise, I'm adding it to my ever-growing list of things to fix 😆

Though I'd say that it'd be even better if the Image.svelte component got rid of double slashes automatically, so you don't have to manually edit any posts because of that change.

MarcoPeretti commented 1 month ago

sure, I can submit a PR but wanted to double-check with you first as, as far as i can tell, the image component is not used. the code is the following:

    {#if post.coverImage}
        <meta property="og:image" content="{siteBaseUrl}{post.coverImage}" />
        <meta name="twitter:image" content="{siteBaseUrl}{post.coverImage}" />
    {/if}

and coverImage is just a string, whose content is set in the blog post(s). I can either update the blog posts and readme file, or create a function that strips the slash from post.coverImage.

thoughts?

matfantinel commented 1 month ago

@MarcoPeretti oh, for the open graph images it really is a simple string. Removing the / from there would work, but stripping double slashes would make it more resilient, which is good since it's a template.

I'd say the only requirement would be to not have to update the content of any blog posts. If it works with both /images/ and images/ that'd be perfect!