onwidget / astrowind

⭕️ AstroWind: A free template using Astro 4.0 and Tailwind CSS. Astro starter theme.
https://astrowind.vercel.app
MIT License
3.45k stars 1.05k forks source link

Can I add a / to the end of post url for cloudflare pages #55

Closed rhuddlestone closed 2 years ago

rhuddlestone commented 2 years ago

Hi

I have deployed a site to Cloudflare pages. When I visit a URL, https://mysite.com/post-name Cloudflare redirects it to https://mysite.com/post-name/ (with the trailing /) as a 308 redirect. This doesn't happen in the Dev environment and appears to be a known "feature" in Cloudflare pages. This is not ideal as it adds an extra request, so some load time.

Is there any way I could add the trailing / to generated links via the theme (e.g., in my blog post list, have the URLs be https//mysite.com/my-post/ instead of https//mysite.com/my-post)?

Thanks

Rob

rhuddlestone commented 2 years ago

Hi

I took a look in the permalinks.js file and made a change.

const createPath = (...params) => '/' + params.filter((el) => !!el).join('/') + '/'; (Added the + '/') at the end of the function.

This works fine in DEV mode, but when I try to build I get

generating static routes ▶ src/pages/index.astro error Invalid URL

Thanks

Rob

prototypa commented 2 years ago

Hi @rhuddlestone

Thanks again for the valuable feedback. That of the trailing slash is something that I had in mind at some point to develop and had not had the opportunity.

I have made a commit (https://github.com/onwidget/astrowind/commit/fa973ceef7612568af5b77d693bd2b3de11066e8) with some changes and I have added a new configuration that allows you to decide whether or not you want to add the slash at the end of the urls.

https://github.com/onwidget/astrowind/blob/main/src/config.mjs#L6

export const SITE = {
  // (...)

  trailingSlash: false,

  // (...)
};

Please try it with the value true and tell me how it works. Thanks.

rhuddlestone commented 2 years ago

Hi @prototypa

That fixed it. Everything working perfectly now.

I tried sending you some money but the buy me a coffee page won't accept my card. Do you have Paypal?

Great work

prototypa commented 2 years ago

Hi @rhuddlestone

Again, thank you very much. You look at very interesting details.

I've already made a fix (https://github.com/onwidget/astrowind/commit/e50a5668a1820ceb9e47398c48a04956601fb172) for pagination to work properly with trailing slash. In case you change the configuration and it doesn't work for you, try to refresh the server (because an astro configuration is referenced from that of the theme)

And don't worry about the rest, the most help is all the feedback you give, that's priceless.

By the way, if you can think of several sections or components or functionalities that you think the theme should have to allow easier the development of a website, please, do not hesitate to open a discussion topic. It would be very helpful, thank you.

rhuddlestone commented 2 years ago

Hi @prototypa

Thanks for the kind words.

Everything is working great now. I am using astrowind for an info blog on WordPress, and I moved it due to the cost os hosting on WordPress and all the bloat.

My load times have gone from >3secs (with expensive hosting) to <400msecs (with free hosting on CloudFlare pages).

I have found these issues via Google Search Console and Ahrefs crawl reports.

As for new features, the two main things are already on your roadmap.

Create component or utilities for latest posts Create component or utilities for related posts

I also see a merge for social share buttons that will be very nice.

Keep up the great work.

prototypa commented 2 years ago

Hi @rhuddlestone

In https://github.com/onwidget/astrowind/commit/2d0687d885f66b616c9dad8c0b7e5e3121d48d2c we add a new LatestPosts.astro widget

https://github.com/onwidget/astrowind/blob/main/src/components/blog/LatestPosts.astro