Add head config validation for meta tags with content#3380
Add head config validation for meta tags with content#3380delucis merged 5 commits intowithastro:mainfrom
head config validation for meta tags with content#3380Conversation
🦋 Changeset detectedLatest commit: 1aa8241 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
✅ Deploy Preview for astro-starlight ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
delucis
left a comment
There was a problem hiding this comment.
I’d forgotten about my own feature request 😄 But that’s why notes are a good idea.
Thanks for picking it up — looks solid!
(I also double checked if there‘s a better way to display the suggested config in the error messages, but Astro’s error renderer doesn’t have code block support, so we can’t easily style it any better than this 👍)
packages/starlight/schemas/head.ts
Outdated
| `The \`head\` configuration includes a \`meta\` tag with \`content\` which is invalid HTML.\n` + | ||
| `You should instead use a \`content\` attribute ` + | ||
| (Object.keys(rest.attrs ?? {}).length === 0 | ||
| ? 'with an additional attribute to identify the kind of metadata it represents ' |
There was a problem hiding this comment.
Wonder if we should hint at common attributes here?
| ? 'with an additional attribute to identify the kind of metadata it represents ' | |
| ? 'with an additional attribute such as `name`, `property`, or `http-equiv` to identify the kind of metadata it represents ' |
I also wondered about linking MDN’s <meta> docs but not sure it’s useful.
There was a problem hiding this comment.
Sounds like a great idea, I wanted to avoid only mentioning name in the sentence but multiple seems helpful 👍
Regarding the link, I initially included it, but it added a lot of content to the message why being not very helpful in contrast to the "code block" imo so I decided to not include it, no strong opinion on that though.
Co-authored-by: delucis <357379+delucis@users.noreply.github.com>
Co-authored-by: delucis <357379+delucis@users.noreply.github.com>
|
Thanks for the review 🙌
Yeah, added a todo about that to play with at some point and see if I can come up with an RFC to improve that, feels like it could be helpful in some cases (and not the first time I wanted something similar). I also tried playing with different output format, e.g. config vs frontmatter, and while it's easy to distinguish between the two, it gets tricky with frontmatter format between JSON, YAML, and TOML, so I think the JSON format should be a good enough indicator of what the fix should look like. |
Oh, good point! I didn’t even put two and two together that this same JSON would display also when you make the error in your frontmatter. I guess we could make the schema dynamic based on where it’s used maybe? So, |
We definitely could, that's even how I initially coded it, then thought about the different Markdown possible format and remove it but I can definitely quickly add it back, and decide how we feel about it 👍 |
I think Astro only supports YAML and TOML? And TOML is pretty recent and I’d guess fairly rare? So YAML seems a safe bet to me. |
I actually like the current one from the screenshots. If you include the - tag: meta
attrs:
name: test:id
content: '1234'Definitely would be clearer with some code block styling to distinguish it.
I’m fairly neutral here as “configuration” could be interpreted OK in the frontmatter context where the lines above show more clearly that it’s about the specific entry. But yeah “frontmatter field” does slightly more hint where to look. |
Co-authored-by: delucis <357379+delucis@users.noreply.github.com>
delucis
left a comment
There was a problem hiding this comment.
Forgot to approve this one but I think it’s looking fantastic 🤩
* main: (26 commits) i18n(ja): resources/themes (withastro#3442) add openstatus showcase (withastro#3436) [ci] release (withastro#3434) Add `head` config validation for `meta` tags with `content` (withastro#3380) Fix Astro Island margins in Markdown (withastro#3340) Ensure tab links span the full tab height (withastro#3427) Move `<summary>` to top of `<details>` for validity (withastro#3423) Run all tests on CI workflow changes (withastro#3433) [ci] format i18n(fr): small rewording and fixes in top-level pages (withastro#3432) i18n(fr): small rewording and fixes in `guides` (withastro#3431) i18n(fr): fix typo and links in `reference` files (withastro#3429) i18n(fr): small rewording in `components` (withastro#3430) [ci] release (withastro#3384) i18n(de): Update `page.lastUpdated` translation to be more in‐line with the English translation (withastro#3416) Remove invalid value attribute from `<select>` (withastro#3421) Convert invalid `<div>` child of `<summary>` to `<span>` (withastro#3422) [i18nIgnore] Fix typo in Spanish docs documentation (withastro#3408) chore(deps): update actions/labeler action to v6.0.1 (withastro#3407) [i18nIgnore] Fix duplicate i18n collection definition (withastro#3409) ...
* main: (72 commits) Showcase: Add Saucer (withastro#3454) i18n(ja): resources/themes (withastro#3442) add openstatus showcase (withastro#3436) [ci] release (withastro#3434) Add `head` config validation for `meta` tags with `content` (withastro#3380) Fix Astro Island margins in Markdown (withastro#3340) Ensure tab links span the full tab height (withastro#3427) Move `<summary>` to top of `<details>` for validity (withastro#3423) Run all tests on CI workflow changes (withastro#3433) [ci] format i18n(fr): small rewording and fixes in top-level pages (withastro#3432) i18n(fr): small rewording and fixes in `guides` (withastro#3431) i18n(fr): fix typo and links in `reference` files (withastro#3429) i18n(fr): small rewording in `components` (withastro#3430) [ci] release (withastro#3384) i18n(de): Update `page.lastUpdated` translation to be more in‐line with the English translation (withastro#3416) Remove invalid value attribute from `<select>` (withastro#3421) Convert invalid `<div>` child of `<summary>` to `<span>` (withastro#3422) [i18nIgnore] Fix typo in Spanish docs documentation (withastro#3408) chore(deps): update actions/labeler action to v6.0.1 (withastro#3407) ...
* main: (87 commits) i18n(ja): sync outdated aside page (withastro#3465) i18n(ja): sync outdated icon reference (withastro#3467) chore(deps): update pnpm/action-setup action to v4.2.0 (withastro#3460) Showcase: Add Saucer (withastro#3454) i18n(ja): resources/themes (withastro#3442) add openstatus showcase (withastro#3436) [ci] release (withastro#3434) Add `head` config validation for `meta` tags with `content` (withastro#3380) Fix Astro Island margins in Markdown (withastro#3340) Ensure tab links span the full tab height (withastro#3427) Move `<summary>` to top of `<details>` for validity (withastro#3423) Run all tests on CI workflow changes (withastro#3433) [ci] format i18n(fr): small rewording and fixes in top-level pages (withastro#3432) i18n(fr): small rewording and fixes in `guides` (withastro#3431) i18n(fr): fix typo and links in `reference` files (withastro#3429) i18n(fr): small rewording in `components` (withastro#3430) [ci] release (withastro#3384) i18n(de): Update `page.lastUpdated` translation to be more in‐line with the English translation (withastro#3416) Remove invalid value attribute from `<select>` (withastro#3421) ...







Description
Just had to debug an issue where a user had a
headconfiguration including ametatag with somecontentwhich is invalid HTML (it's a void element) and found out we already have a feature request to better handle this case so I decided to implement it.This PR adds a validation steps for
metatags in theheadconfig to ensure thatcontentis not provided and displays a friendly error message if it is.The error message is different if some
attrsare provided or not, to help users fix their config more easily:attrsattrs