methanol 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,68 +18,22 @@
18
18
  * under the License.
19
19
  */
20
20
 
21
- import { HTMLRenderer as R } from 'methanol'
22
- import { renderToc } from './components/ThemeToCContainer.static.jsx'
21
+ import { HTMLRenderer as R, DOCTYPE_HTML } from 'methanol'
22
+ import { renderToc } from '../components/ThemeToCContainer.static.jsx'
23
+ import { renderNavTree } from './nav-tree.jsx'
23
24
 
24
- const DOCHTML = R.rawHTML`<!DOCTYPE html>`
25
-
26
- const renderPageTree = (nodes = [], currentRoute, depth = 0) => {
27
- const items = []
28
- let hasActive = false
29
- for (const node of nodes) {
30
- const nodeRoute = node.routeHref || ''
31
- if (node.type === 'directory') {
32
- const label = node.title || node.name
33
- const isActive = nodeRoute === currentRoute
34
- const href = node.routeHref
35
- const childResult = renderPageTree(node.children || [], currentRoute, depth + 1)
36
- const isOpen = depth < 1 || isActive || childResult.hasActive
37
- if (isOpen) hasActive = true
38
- const header = href ? (
39
- <a class={isActive ? 'nav-dir-link active' : 'nav-dir-link'} href={href}>
40
- {label}
41
- </a>
42
- ) : (
43
- <span class="nav-dir-label">{label}</span>
44
- )
45
- items.push(
46
- <li class={isActive ? 'is-active' : null}>
47
- <details class="sidebar-collapsible" open={isOpen ? true : null}>
48
- <summary class="sb-dir-header">{header}</summary>
49
- {childResult.items.length ? <ul data-depth={depth + 1}>{childResult.items}</ul> : null}
50
- </details>
51
- </li>
52
- )
53
- continue
54
- }
55
- const label = node.title || (node.isIndex ? 'Home' : node.name)
56
- const isActive = nodeRoute === currentRoute
57
- if (isActive) hasActive = true
58
- const href = node.routeHref
59
- items.push(
60
- <li>
61
- <a class={isActive ? 'active' : null} href={href}>
62
- {label}
63
- </a>
64
- </li>
65
- )
66
- }
67
- return { items, hasActive }
68
- }
69
-
70
- const PAGE_TEMPLATE = ({ PageContent, ExtraHead, components, ctx }) => {
25
+ const PAGE_TEMPLATE = async ({ PageContent, ExtraHead, components, ctx }) => {
71
26
  const page = ctx.page
72
27
  const pagesByRoute = ctx.pagesByRoute
73
28
  const pages = ctx.pages || []
74
29
  const pagesTree = ctx.pagesTree || []
75
30
  const siteName = ctx.site.name || 'Methanol Site'
76
31
  const title = page.title || siteName
77
- const currentRoute = page.routeHref || ''
78
- const baseHref = page.routeHref === '/404' ? ctx.site.base || '/' : null
32
+ const baseHref =
33
+ page.routeHref === '/404' || page.routeHref === '/offline' ? ctx.site.base || '/' : null
79
34
  const toc = page.toc?.length ? renderToc(page.toc) : null
80
35
  const hasToc = Boolean(toc)
81
36
  const layoutClass = hasToc ? 'layout-container' : 'layout-container no-toc'
82
- const tree = renderPageTree(pagesTree, currentRoute, 0)
83
37
  const { ThemeSearchBox, ThemeColorSwitch, ThemeAccentSwitch, ThemeToCContainer } = components
84
38
  const rootPage = pagesByRoute.get('/') || pages.find((entry) => entry.routeHref === '/')
85
39
  const pageFrontmatter = page.frontmatter || {}
@@ -146,9 +100,10 @@ const PAGE_TEMPLATE = ({ PageContent, ExtraHead, components, ctx }) => {
146
100
  </div>
147
101
  </div>
148
102
  ) : null
103
+
149
104
  return (
150
105
  <>
151
- {DOCHTML}
106
+ {DOCTYPE_HTML}
152
107
  <html lang={htmlLang}>
153
108
  <head>
154
109
  <meta charset="UTF-8" />
@@ -244,7 +199,7 @@ const PAGE_TEMPLATE = ({ PageContent, ExtraHead, components, ctx }) => {
244
199
  {pagefindEnabled ? <ThemeSearchBox options={pagefindOptions} /> : null}
245
200
  </div>
246
201
  <nav>
247
- <ul data-depth="0">{tree.items}</ul>
202
+ <ul data-depth="0">{renderNavTree(pagesTree, page.routePath)}</ul>
248
203
  </nav>
249
204
  <div class="sidebar-footer">
250
205
  {languageSelector}
@@ -294,7 +249,7 @@ const PAGE_TEMPLATE = ({ PageContent, ExtraHead, components, ctx }) => {
294
249
  <span style="margin: 0 0.5rem; opacity: 0.5;">•</span>
295
250
  </>
296
251
  ) : null}
297
- Updated: {page.updatedAt || '-'}
252
+ Updated: {page.stats.updatedAt || '-'}
298
253
  </div>
299
254
  <div class="page-meta-item">
300
255
  Powered by{' '}
File without changes