Skip to content

Commit

Permalink
fix: pagefind data attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo committed Dec 24, 2024
1 parent 29cdb81 commit 651702d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-hairs-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': patch
---

Fixes an issue preventing Pagefind to be disabled using the `pagefind` frontmatter field.
15 changes: 9 additions & 6 deletions packages/starlight/components/Page.astro
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ const pagefindEnabled =
!Astro.props.entry.slug.endsWith('/404') &&
Astro.props.entry.data.pagefind !== false;
const dataAttributes: DOMStringMap = { 'data-theme': 'dark' };
if (Boolean(Astro.props.toc)) dataAttributes['data-has-toc'] = '';
if (Astro.props.hasSidebar) dataAttributes['data-has-sidebar'] = '';
if (Boolean(Astro.props.entry.data.hero)) dataAttributes['data-has-hero'] = '';
const htmlDataAttributes: DOMStringMap = { 'data-theme': 'dark' };
if (Boolean(Astro.props.toc)) htmlDataAttributes['data-has-toc'] = '';
if (Astro.props.hasSidebar) htmlDataAttributes['data-has-sidebar'] = '';
if (Boolean(Astro.props.entry.data.hero)) htmlDataAttributes['data-has-hero'] = '';
const mainDataAttributes: DOMStringMap = {};
if (pagefindEnabled) mainDataAttributes['data-pagefind-body'] = '';
---

<html lang={Astro.props.lang} dir={Astro.props.dir} {...dataAttributes}>
<html lang={Astro.props.lang} dir={Astro.props.dir} {...htmlDataAttributes}>
<head>
<Head {...Astro.props} />
<style>
Expand Down Expand Up @@ -82,7 +85,7 @@ if (Boolean(Astro.props.entry.data.hero)) dataAttributes['data-has-hero'] = '';
<TwoColumnContent {...Astro.props}>
<PageSidebar slot="right-sidebar" {...Astro.props} />
<main
data-pagefind-body={pagefindEnabled}
{...mainDataAttributes}
lang={Astro.props.entryMeta.lang}
dir={Astro.props.entryMeta.dir}
>
Expand Down

0 comments on commit 651702d

Please sign in to comment.