feat: add draft frontmatter flag to withhold guides from publishing - #1027
feat: add draft frontmatter flag to withhold guides from publishing#1027LeaVerou wants to merge 1 commit into
draft frontmatter flag to withhold guides from publishing#1027Conversation
Guides can set `draft: true` (or any truthy value, e.g. `draft: future`) in frontmatter to be excluded from all distribution (search index, README, megaskill) without deleting them. The value is intentionally not validated. Evals are unaffected — a draft guide with eval artifacts still runs. `isPublished` (real content + not draft) is computed once as a guide-inventory property, consumed by all three build paths. Part of #1017
06fb1a3 to
fbf6231
Compare
rviscomi
left a comment
There was a problem hiding this comment.
Supportive of this change so LGTMing but it'd be good to get a technical review from @paulirish
| const { data = {}, content = '' } = guideContent ? matter(guideContent) : {}; | ||
| const hasFrontmatter = Object.keys(data).length > 0 || guideContent.startsWith('---'); | ||
| const hasContent = content.replace(/<!--[\s\S]*?-->/g, '').trim().length > 0; | ||
| const isStub = hasFrontmatter; |
There was a problem hiding this comment.
Does this treat every guide with frontmatter as a stub? Should we exclude guides with content?
| const isStub = hasFrontmatter; | |
| const isStub = hasFrontmatter && !hasContent; |
There was a problem hiding this comment.
Apparently, this was the existing logic! See
modern-web-guidance-src/lib/guide-validation.ts
Lines 481 to 482 in 2a100bb
It surprised me too. It doesn't seem to be a latent bug, just a poorly named variable. When the current code needs to actually test stub-ness, it adds conditions, e.g. see
modern-web-guidance-src/lib/guide-validation.ts
Lines 566 to 567 in 2a100bb
| const hasContent = content.replace(/<!--[\s\S]*?-->/g, '').trim().length > 0; | ||
| const isStub = hasFrontmatter; | ||
| const hasGuide = hasContent; | ||
| const draft = data.draft ?? false; |
There was a problem hiding this comment.
What happens if someone uses a string value like "false", would that be interpreted as a truthy value?
There was a problem hiding this comment.
Yes, but that would only happen if they use explicit quotes in the frontmatter, i.e. draft: "false". Should we special-case this? Any other values to special case?
Closes #1017
Adds:
draftfrontmatter option. Guides can setdraft: true(or any truthy value, e.g.draft: future) in frontmatter to be excluded from all distribution (search index, README, megaskill) without deleting them. Evals are unaffected — a draft guide with eval artifacts still runs.The value is intentionally not validated (per Frontmatter option to prevent guides from being published #1017 (comment) )
draftandisPublishedproperties inGuideInventory.isPublished(real content + not draft) is computed once as a guide-inventory property, consumed by all three build paths.I also did a little minor refactoring to make the logic and dependencies in
inventoryGuide()easier to follow, but I can revert it if needed.Note: I kept the logic as-is to avoid regressions, but it's a little confusing that
isStubis true even for a fully fleshed out guide…