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

fix(markdown): file.url fixes #3198

Merged
merged 7 commits into from
Apr 25, 2022
Merged

fix(markdown): file.url fixes #3198

merged 7 commits into from
Apr 25, 2022

Conversation

JuanM04
Copy link
Contributor

@JuanM04 JuanM04 commented Apr 24, 2022

Changes

  • file.url now respects trailingSlash, adding a / at the end when it's set to "always"
  • file.url now respects base (needed to change the default of base from ./ to /)
  • Minor fix to this RegEx:
- fileId.replace(/^.*\/pages\//, sitePathname)
+ fileId.replace(/^.*?\/pages\//, sitePathname)

The ? makes the selection "lazy", which means that it will replace the shortest match. For example:

const fileId = "src/pages/docs/pages/how-to-create-a-page.md"

console.log(fileId.replace(/^.*?\/pages\//, '')) // docs/pages/how-to-create-a-page.md
console.log(fileId.replace(/^.*\/pages\//, '')) // how-to-create-a-page.md

Testing

Docs

@changeset-bot
Copy link

changeset-bot bot commented Apr 24, 2022

🦋 Changeset detected

Latest commit: bbf612e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
astro Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Apr 24, 2022
@FredKSchott
Copy link
Member

LGTM! Would love to see an added test since this feels like something that we could accidentally regress pretty easily

@github-actions github-actions bot added the test label Apr 25, 2022
@JuanM04
Copy link
Contributor Author

JuanM04 commented Apr 25, 2022

@FredKSchott I've added some test and also made it work with base! While doing that, I've changed the default of base from ./ to / (so now, base always starts with a /)

Copy link
Member

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

Agreed, that makes way more sense. Most of our tests are testing the default, so if they are passing I have confidence that this change works. Mind confirming that the dev and preview commands work with an example template to be extra sure? If so the LGTM to merge!

@JuanM04
Copy link
Contributor Author

JuanM04 commented Apr 25, 2022

Mind confirming that the dev and preview commands work with an example template to be extra sure?

I've tried with a few and all seems normal!

@JuanM04 JuanM04 merged commit 1a86e77 into main Apr 25, 2022
@JuanM04 JuanM04 deleted the juanm04/fix-markdown-url branch April 25, 2022 16:38
@FredKSchott
Copy link
Member

woo! sgtm

@github-actions github-actions bot mentioned this pull request Apr 25, 2022
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* fix(markdown): file.url fixes

* Added tests

* Changed the default of `base` from `./` to `/`

* Make the url work with subpath

* Changeset

* Forgot to change this comparison
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants