Skip to content

feat: add draft frontmatter flag to withhold guides from publishing - #1027

Open
LeaVerou wants to merge 1 commit into
mainfrom
guide-draft-flag
Open

feat: add draft frontmatter flag to withhold guides from publishing#1027
LeaVerou wants to merge 1 commit into
mainfrom
guide-draft-flag

Conversation

@LeaVerou

Copy link
Copy Markdown
Collaborator

Closes #1017

Adds:

  • draft frontmatter option. 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. 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) )
  • draft and isPublished properties in GuideInventory. 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 isStub is true even for a fully fleshed out guide…

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

@rviscomi rviscomi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Supportive of this change so LGTMing but it'd be good to get a technical review from @paulirish

Comment thread lib/guide-validation.ts
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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this treat every guide with frontmatter as a stub? Should we exclude guides with content?

Suggested change
const isStub = hasFrontmatter;
const isStub = hasFrontmatter && !hasContent;

@LeaVerou LeaVerou Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Apparently, this was the existing logic! See

if (hasFrontmatter) {
isStub = true;

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
if (!inv.hasGuide && !inv.isStub) return 'incomplete';
if (inv.isStub && !inv.hasGuide) return 'stub';

Comment thread lib/guide-validation.ts
const hasContent = content.replace(/<!--[\s\S]*?-->/g, '').trim().length > 0;
const isStub = hasFrontmatter;
const hasGuide = hasContent;
const draft = data.draft ?? false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens if someone uses a string value like "false", would that be interpreted as a truthy value?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Frontmatter option to prevent guides from being published

2 participants