File tree 5 files changed +54
-9
lines changed
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"
22
22
import Comments from "./Comments"
23
23
import NavigationLinks from "./NavigationLinks"
24
24
import Drawer from "./Drawer"
25
+ import NavbarWrapper from "./NavbarWrapper"
25
26
26
27
export {
27
28
ArticleTitle ,
@@ -39,6 +40,7 @@ export {
39
40
Explorer ,
40
41
TagList ,
41
42
Graph ,
43
+ NavbarWrapper ,
42
44
Backlinks ,
43
45
Search ,
44
46
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 {
36
36
afterDOMLoaded : new Set < string > ( ) ,
37
37
}
38
38
39
+ function normalizeResource ( resource : string | string [ ] | undefined ) : string [ ] {
40
+ if ( ! resource ) return [ ]
41
+ if ( Array . isArray ( resource ) ) return resource
42
+ return [ resource ]
43
+ }
44
+
39
45
for ( const component of allComponents ) {
40
46
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 ) )
50
54
}
51
55
52
56
return {
Original file line number Diff line number Diff line change @@ -63,3 +63,10 @@ export interface StaticResources {
63
63
css : CSSResource [ ]
64
64
js : JSResource [ ]
65
65
}
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