Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use relative uris for posts. #71

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Use relative uris for posts. #71

wants to merge 4 commits into from

Conversation

evert
Copy link
Contributor

@evert evert commented Oct 9, 2024

This tripped me up during testing. All links went to the production URL, so it looked like the new page i was adding was 404ing, but I didn't realize I was no longer on the same domain.

Makes more sense to make these relative I think!

Copy link

netlify bot commented Oct 9, 2024

Deploy Preview for blogtorontojscom ready!

Name Link
🔨 Latest commit af44789
🔍 Latest deploy log https://app.netlify.com/sites/blogtorontojscom/deploys/670f3cba69bedc00081818f4
😎 Deploy Preview https://deploy-preview-71--blogtorontojscom.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

This tripped me up during testing. All links went to the production URL.
Makes more sense to make these relative I think!
@evert evert changed the title relative uris Use relative uris for posts. Oct 9, 2024
@madcampos
Copy link
Collaborator

What command were you using to test it?

If you do use start or dev, it should correctly point to localhost, whereas preview will "mess up" the urls. But that is by design.

preview is the outlier as it will allow you to check on localhost, but will build for production, which should point to the live url.

@@ -62,7 +62,7 @@ const {
posts.map((post) => (
<PostCard
variant="large"
url={`${BLOG_URL}${post.url}`}
url={post.url}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check that post.url correctly resolves to an absolute url so we don't have inexistant relative urls?

Copy link
Contributor Author

@evert evert Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's a relative URL, and that's what you want here I think!

But it does resolve and made clicking through the site while testing a lot easier.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is that we have relative URLs like: ./2024/10/some-post and that will break some pages like the tags pages. For example, if you go to /tags/web-development and have the relative URL post, it will not work as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no, the URLs start with a slash! So that should be good

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked, the urls don't start with slashes... 😕

a screenshot of a terminal logging urls, showing all of them start with a number like 2024..., etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an example of an url on the tags page:

url showing: https://localhost:3000/tags/2024/09/new-blog

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof sorry, I must have looked at this wrong. Will fix this PR!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for checking

Copy link
Collaborator

@madcampos madcampos Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, I just fixed the issue on the root. Take a look at this branch: relative-uris...fix/post-urls

It also fixes the issues with the rss feed (turns out it was missing a namespace and the reference to get the posts was wrong)

@evert
Copy link
Contributor Author

evert commented Oct 16, 2024

Fixed! And I also changed a few more instances of this issue

@evert evert requested a review from madcampos October 16, 2024 04:08
@madcampos madcampos self-requested a review October 16, 2024 16:38
Copy link
Collaborator

@madcampos madcampos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me be very pedantic here: I think it would be better if we fix this at the source, by making post.url start with a slash than fix in multiple places.

Another option would be to add a url formatting utility, but that may be more complex.

Aside from that it looks good to me, feel free to merge and we can make it more generic in a next PR.

@evert
Copy link
Contributor Author

evert commented Oct 16, 2024

I'm ok with pedantic! I assumed post.url was a built-in and not a custom made thing for this blog. Happy to keep workshopping this!

@madcampos
Copy link
Collaborator

It is a built-in, but we are overriding it at the source to include the year and month.
Take a look at utils/post.ts. We can add a leading slash here.

I made this change and updated some other places on the branch fix/post-urls, check out those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants