-
Notifications
You must be signed in to change notification settings - Fork 10.4k
[Docs Site] Decode HTML entities and strip Markdown from page descriptions #19350
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
Conversation
| } | ||
| Astro.props.entry.data.description ??= await getPageDescription( | ||
| Astro.props.entry.data.description = await getPageDescription( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We used to do if (entry.data.description) return entry.data.description; in getPageDescription but that didn't do anything - because we never used this function if that property existed.
That was a bug, but also fine since we never would have changed it. Now we are transforming it so removed ??.
| import { remark } from "remark"; | ||
| import strip from "strip-markdown"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could technically be done in a lot more lines with marked but most of their discussions recommend using other libraries, like strip-markdown.
| const paragraph = dom.querySelector(":root > p"); | ||
|
|
||
| if (description) return description.innerText; | ||
| if (paragraph) description = he.decode(paragraph.innerText); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<body> -> <body>
| let description = undefined; | ||
|
|
||
| if (entry.data.description) { | ||
| const file = await remark().use(strip).process(entry.data.description); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[`workers-rs` crate](https://github.com/cloudflare/workers-rs)` -> `workers-rs crate`
Deploying cloudflare-docs with
|
| Latest commit: |
03be761
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f2c45653.cloudflare-docs-7ou.pages.dev |
| Branch Preview URL: | https://kian-pcx-14260.cloudflare-docs-7ou.pages.dev |
|
Files with changes (up to 15)
|
kodster28
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Output lgtm + this should only affect descriptions so it's a low-risk change.
Summary
Before:
After: