Skip to content
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

feat: reduce initial css load #145

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 8 additions & 65 deletions src/components/Search.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
---
// Heavy inspiration taken from Astro Starlight -> https://github.com/withastro/starlight/blob/main/packages/starlight/components/Search.astro

import "@pagefind/default-ui/css/ui.css";
---

<site-search id="search" class="ms-auto">
<button
data-open-modal
Expand Down Expand Up @@ -115,6 +109,14 @@ import "@pagefind/default-ui/css/ui.css";
showSubResults: true,
});
});

onIdle(async () => {
const searchStyles = await import('../styles/search.css?inline');
const styleTag = document.createElement('style')
styleTag.id = "search";
styleTag.innerHTML = searchStyles.default || ''
document.head.appendChild(styleTag)
})
});

// close modal and clear input on view-transtion
Expand All @@ -130,65 +132,6 @@ import "@pagefind/default-ui/css/ui.css";
customElements.define("site-search", SiteSearch);
</script>

<style is:global>
:root {
--pagefind-ui-font: inherit;
}

#cactus__search .pagefind-ui__search-clear {
width: calc(60px * var(--pagefind-ui-scale));
padding: 0;
background-color: transparent;
overflow: hidden;
}
#cactus__search .pagefind-ui__search-clear:focus {
outline: 1px solid theme("colors.accent-2");
}
#cactus__search .pagefind-ui__search-clear::before {
content: "";
-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='currentColor' %3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M6 18L18 6M6 6l12 12'%3E%3C/path%3E%3C/svg%3E")
center / 60% no-repeat;
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='currentColor' %3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M6 18L18 6M6 6l12 12'%3E%3C/path%3E%3C/svg%3E")
center / 60% no-repeat;
background-color: theme("colors.accent");
display: block;
width: 100%;
height: 100%;
}

#cactus__search .pagefind-ui__result {
border: 0;
}

#cactus__search .pagefind-ui__result-link {
background-size: 100% 6px;
background-position: bottom;
background-repeat: repeat-x;
background-image: linear-gradient(
transparent,
transparent 5px,
theme("colors.textColor") 5px,
theme("colors.textColor")
);
}

#cactus__search .pagefind-ui__result-link:hover {
text-decoration: none;
background-image: linear-gradient(
transparent,
transparent 4px,
theme("colors.link") 4px,
theme("colors.link")
);
}

#cactus__search mark {
color: theme("colors.quote");
background-color: transparent;
font-weight: 600;
}
</style>

<style>
#cactus__search {
--pagefind-ui-primary: theme("colors.accent");
Expand Down
58 changes: 58 additions & 0 deletions src/styles/search.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@import "@pagefind/default-ui/css/ui.css";

:root {
--pagefind-ui-font: inherit;
}

#cactus__search .pagefind-ui__search-clear {
width: calc(60px * var(--pagefind-ui-scale));
padding: 0;
background-color: transparent;
overflow: hidden;
}
#cactus__search .pagefind-ui__search-clear:focus {
outline: 1px solid theme("colors.accent-2");
}
#cactus__search .pagefind-ui__search-clear::before {
content: "";
-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='currentColor' %3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M6 18L18 6M6 6l12 12'%3E%3C/path%3E%3C/svg%3E")
center / 60% no-repeat;
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='currentColor' %3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M6 18L18 6M6 6l12 12'%3E%3C/path%3E%3C/svg%3E")
center / 60% no-repeat;
background-color: theme("colors.accent");
display: block;
width: 100%;
height: 100%;
}

#cactus__search .pagefind-ui__result {
border: 0;
}

#cactus__search .pagefind-ui__result-link {
background-size: 100% 6px;
background-position: bottom;
background-repeat: repeat-x;
background-image: linear-gradient(
transparent,
transparent 5px,
theme("colors.textColor") 5px,
theme("colors.textColor")
);
}

#cactus__search .pagefind-ui__result-link:hover {
text-decoration: none;
background-image: linear-gradient(
transparent,
transparent 4px,
theme("colors.link") 4px,
theme("colors.link")
);
}

#cactus__search mark {
color: theme("colors.quote");
background-color: transparent;
font-weight: 600;
}