File tree Expand file tree Collapse file tree 5 files changed +54
-9
lines changed
Expand file tree Collapse file tree 5 files changed +54
-9
lines changed Original file line number Diff line number Diff line change 1+ import { concatenateResources } from "../util/resources"
2+ import { QuartzComponent , QuartzComponentConstructor , QuartzComponentProps } from "./types"
3+ import style from "./styles/navbarwrapper.scss"
4+ interface Options {
5+ components : QuartzComponent [ ]
6+ }
7+
8+ export default ( ( opts : Options ) => {
9+ const NavbarWrapper : QuartzComponent = ( props : QuartzComponentProps ) => {
10+ return (
11+ < div class = "navbar-wrapper" >
12+ { opts ?. components . map ( ( Component ) => {
13+ return < Component { ...props } > </ Component >
14+ } ) }
15+ </ div >
16+ )
17+ }
18+ NavbarWrapper . afterDOMLoaded = concatenateResources (
19+ ...opts . components . map ( ( c ) => c . afterDOMLoaded ) ,
20+ )
21+ NavbarWrapper . beforeDOMLoaded = concatenateResources (
22+ ...opts . components . map ( ( c ) => c . beforeDOMLoaded ) ,
23+ )
24+ NavbarWrapper . css = concatenateResources ( ...opts . components . map ( ( c ) => c . css ) , style )
25+ return NavbarWrapper
26+ } ) satisfies QuartzComponentConstructor < Options >
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import Breadcrumbs from "./Breadcrumbs"
2222import Comments from "./Comments"
2323import NavigationLinks from "./NavigationLinks"
2424import Drawer from "./Drawer"
25+ import NavbarWrapper from "./NavbarWrapper"
2526
2627export {
2728 ArticleTitle ,
@@ -39,6 +40,7 @@ export {
3940 Explorer ,
4041 TagList ,
4142 Graph ,
43+ NavbarWrapper ,
4244 Backlinks ,
4345 Search ,
4446 Footer ,
Original file line number Diff line number Diff line change 1+ .navbar-wrapper {
2+ display : flex ;
3+ align-items : center ;
4+ justify-content : center ;
5+ gap : 10px ;
6+ }
Original file line number Diff line number Diff line change @@ -36,17 +36,21 @@ function getComponentResources(ctx: BuildCtx): ComponentResources {
3636 afterDOMLoaded : new Set < string > ( ) ,
3737 }
3838
39+ function normalizeResource ( resource : string | string [ ] | undefined ) : string [ ] {
40+ if ( ! resource ) return [ ]
41+ if ( Array . isArray ( resource ) ) return resource
42+ return [ resource ]
43+ }
44+
3945 for ( const component of allComponents ) {
4046 const { css, beforeDOMLoaded, afterDOMLoaded } = component
41- if ( css ) {
42- componentResources . css . add ( css )
43- }
44- if ( beforeDOMLoaded ) {
45- componentResources . beforeDOMLoaded . add ( beforeDOMLoaded )
46- }
47- if ( afterDOMLoaded ) {
48- componentResources . afterDOMLoaded . add ( afterDOMLoaded )
49- }
47+ const normalizedCss = normalizeResource ( css )
48+ const normalizedBeforeDOMLoaded = normalizeResource ( beforeDOMLoaded )
49+ const normalizedAfterDOMLoaded = normalizeResource ( afterDOMLoaded )
50+
51+ normalizedCss . forEach ( ( c ) => componentResources . css . add ( c ) )
52+ normalizedBeforeDOMLoaded . forEach ( ( b ) => componentResources . beforeDOMLoaded . add ( b ) )
53+ normalizedAfterDOMLoaded . forEach ( ( a ) => componentResources . afterDOMLoaded . add ( a ) )
5054 }
5155
5256 return {
Original file line number Diff line number Diff line change @@ -63,3 +63,10 @@ export interface StaticResources {
6363 css : CSSResource [ ]
6464 js : JSResource [ ]
6565}
66+
67+ export type StringResource = string | string [ ] | undefined
68+ export function concatenateResources ( ...resources : StringResource [ ] ) : StringResource {
69+ return resources
70+ . filter ( ( resource ) : resource is string | string [ ] => resource !== undefined )
71+ . flat ( )
72+ }
You can’t perform that action at this time.
0 commit comments