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

Removes trailing dash from generated slugs in markdown #3044

Merged
merged 7 commits into from
Jul 16, 2022

Conversation

RafidMuhymin
Copy link
Member

@RafidMuhymin RafidMuhymin commented Apr 9, 2022

Changes

If the slugs generated from headers in markdown end with a trailing dash, the dash will be removed. This change will improve slug generation in the following cases.

### `<BackgroundImage />`

Currently, the generated slug will be backgroundimage-. But with this change, it will be just backgroundimage.

Testing

The change was tested locally.

Docs

@changeset-bot
Copy link

changeset-bot bot commented Apr 9, 2022

🦋 Changeset detected

Latest commit: 6f53106

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

This PR includes changesets to release 10 packages
Name Type
@astrojs/markdown-remark Minor
astro Patch
@e2e/astro-component Patch
@e2e/lit-component Patch
@e2e/preact-component Patch
@e2e/react-component Patch
@e2e/solid-component Patch
@e2e/svelte-component Patch
@e2e/e2e-tailwindcss Patch
@e2e/ts-resolution 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 feat: markdown Related to Markdown (scope) label Apr 9, 2022
@RafidMuhymin RafidMuhymin changed the title fixed header slugs in markdown if ends with a dash fixed generated slugs in markdown that ends with a dash Apr 9, 2022
@JuanM04
Copy link
Contributor

JuanM04 commented Apr 9, 2022

How does this play with other plugins? For example, a plugin that adds a table of content may generate slugs with trailing dash, making it unusable (or not, I'm just asking)

@RafidMuhymin RafidMuhymin changed the title fixed generated slugs in markdown that ends with a dash Removes trailing dash from generated slugs in markdown Apr 10, 2022
@RafidMuhymin
Copy link
Member Author

@JuanM04 This change will apply to all the plugins that generate slugs from headings.

Copy link
Contributor

@JuanM04 JuanM04 left a comment

Choose a reason for hiding this comment

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

Let's just remove trailing dashes only when we are generating them. Otherwise, we should let the plugins do their own. Something like this:

if (!node.properties) node.properties = {};

if (!node.properties.id) {
	let slug = slugger.slug(text);
	if (slug.endsWith('-')) slug = slug.slice(0, -1);
	node.properties.id = slug;
}

headers.push({ depth, slug: node.properties.id, text });

@@ -0,0 +1,5 @@
---
'@astrojs/markdown-remark': patch
Copy link
Member

Choose a reason for hiding this comment

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

the fact that this could break some existing URL hashes means that we'll need to:

  • think this through a bit more than normal: we want to make this change once and only once, if we can help it.
  • time it with other breaking changes, if we have any to go out together
  • message it as a potentially breaking change in the changelog

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. You are right Fred. But then should it be a minor or major change? Will there be a v0.27?

@RafidMuhymin
Copy link
Member Author

@JuanM04 I don't see any difference between the code you provided and the current code. Can you explain what that changes?

@JuanM04
Copy link
Contributor

JuanM04 commented Apr 12, 2022

@RafidMuhymin yeah, sorry, I had a typo. That code only trims the dash if the slug was generated by us instead of a custom plugin

@RafidMuhymin
Copy link
Member Author

Yeah, you are right @JuanM04 ! Made some changes to the PR!

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.

I still want to see this merged, but we may want to hold off until v1.0.0-rc.1, where we can bundle a bunch of final breaking changes together one last time.

@RafidMuhymin I don't want you to have to keep this PR up to date forever, so if you can change this PR to merge into v1-rc branch instead of main, I can help you merge and help keep it up to date, as we move closer to our RC!

@FredKSchott FredKSchott modified the milestone: v1.0 May 19, 2022
@matthewp
Copy link
Contributor

@RafidMuhymin are you planning on updating this? Thanks!

@RafidMuhymin
Copy link
Member Author

@matthewp should I open a new PR at v1-rc or update this PR?

@FredKSchott
Copy link
Member

Yup, I'd originally asked RafidMuhymin to hold off on merging this since it's a tiny but breaking change. Now that we're getting ready to switch main to RC with Vite 3, so this is almost ready to merge. Rafid, if you could resolve merge conflicts that would be great.

Copy link
Contributor

@JuanM04 JuanM04 left a comment

Choose a reason for hiding this comment

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

Looks good! @FredKSchott, the changeset needs to be major, minor or patch?

@FredKSchott
Copy link
Member

minor is probably best, since that package is v0 you would use minor (v0.11 -> v0.12) to mark a breaking change

@RafidMuhymin
Copy link
Member Author

Merging this PR.

@RafidMuhymin RafidMuhymin merged commit 8530cce into withastro:main Jul 16, 2022
@astrobot-houston astrobot-houston mentioned this pull request Jul 16, 2022
@FredKSchott
Copy link
Member

We want to hold off on any breaking changes until #3570 is merged.

I'll revert this on main, and then re-revert after #3570 is merged, sometime in the next 24 hours or so.

FredKSchott added a commit that referenced this pull request Jul 18, 2022
FredKSchott added a commit that referenced this pull request Jul 18, 2022
FredKSchott added a commit that referenced this pull request Jul 18, 2022
FredKSchott pushed a commit that referenced this pull request Jul 19, 2022
* fixed header slugs in markdown if ends with a dash

* added changeset

* removes trailing dash only if slug was created

* updated test

* updated change level from patch to minor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: markdown Related to Markdown (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants