methanol 0.0.14 → 0.0.15

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.
Files changed (38) hide show
  1. package/index.js +1 -0
  2. package/package.json +1 -1
  3. package/src/build-system.js +1 -0
  4. package/src/config.js +33 -3
  5. package/src/dev-server.js +21 -13
  6. package/src/pages-index.js +42 -0
  7. package/src/pages.js +1 -0
  8. package/src/reframe.js +1 -1
  9. package/src/state.js +8 -0
  10. package/src/text-utils.js +60 -0
  11. package/src/vite-plugins.js +9 -0
  12. package/src/workers/build-pool.js +1 -0
  13. package/themes/blog/README.md +26 -0
  14. package/themes/blog/components/CategoryView.client.jsx +164 -0
  15. package/themes/blog/components/CategoryView.static.jsx +35 -0
  16. package/themes/blog/components/CollectionView.client.jsx +151 -0
  17. package/themes/blog/components/CollectionView.static.jsx +37 -0
  18. package/themes/blog/components/PostList.client.jsx +92 -0
  19. package/themes/blog/components/PostList.static.jsx +36 -0
  20. package/themes/blog/components/ThemeSearchBox.client.jsx +427 -0
  21. package/themes/blog/components/ThemeSearchBox.static.jsx +40 -0
  22. package/themes/blog/index.js +40 -0
  23. package/themes/blog/pages/404.mdx +12 -0
  24. package/themes/blog/pages/about.mdx +14 -0
  25. package/themes/blog/pages/categories.mdx +6 -0
  26. package/themes/blog/pages/collections.mdx +6 -0
  27. package/themes/blog/pages/index.mdx +16 -0
  28. package/themes/blog/pages/offline.mdx +11 -0
  29. package/themes/blog/sources/style.css +579 -0
  30. package/themes/blog/src/date-utils.js +28 -0
  31. package/themes/blog/src/heading.jsx +37 -0
  32. package/themes/blog/src/layout-categories.jsx +66 -0
  33. package/themes/blog/src/layout-collections.jsx +65 -0
  34. package/themes/blog/src/layout-home.jsx +66 -0
  35. package/themes/blog/src/layout-post.jsx +42 -0
  36. package/themes/blog/src/page.jsx +152 -0
  37. package/themes/blog/src/post-utils.js +83 -0
  38. package/themes/default/src/page.jsx +1 -1
@@ -0,0 +1,151 @@
1
+ /* Copyright Yukino Song, SudoMaker Ltd.
2
+ *
3
+ * Licensed to the Apache Software Foundation (ASF) under one
4
+ * or more contributor license agreements. See the NOTICE file
5
+ * distributed with this work for additional information
6
+ * regarding copyright ownership. The ASF licenses this file
7
+ * to you under the Apache License, Version 2.0 (the
8
+ * "License"); you may not use this file except in compliance
9
+ * with the License. You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+
21
+ import { signal, $, For, If, onCondition } from 'refui'
22
+ import pages from 'methanol:pages'
23
+ import { formatDate } from '../src/date-utils.js'
24
+
25
+ const rawPages = Array.isArray(pages) ? pages : []
26
+ const isPostPage = (p) => {
27
+ if (!p?.routeHref) return false
28
+ if (p.routeHref === '/' || p.routeHref === '/404' || p.routeHref === '/offline') return false
29
+ if (p.routeHref.startsWith('/.methanol')) return false
30
+ return true
31
+ }
32
+ const getCollection = (p) => {
33
+ if (p.collection) return p.collection
34
+ if (!p.dir) return null
35
+ return p.dir.split('/')[0]
36
+ }
37
+ const resolvePosts = () => {
38
+ const list = rawPages.filter(isPostPage)
39
+ list.sort((a, b) => {
40
+ const dateA = new Date(a.frontmatter?.date || a.stats?.createdAt || 0)
41
+ const dateB = new Date(b.frontmatter?.date || b.stats?.createdAt || 0)
42
+ return dateB - dateA
43
+ })
44
+ return list.map((p) => ({
45
+ title: p.title,
46
+ routeHref: p.routeHref,
47
+ frontmatter: p.frontmatter || {},
48
+ stats: p.stats || {},
49
+ excerpt: p.excerpt || p.frontmatter?.excerpt || '',
50
+ collection: getCollection(p)
51
+ }))
52
+ }
53
+ const allPosts = resolvePosts()
54
+ const defaultCollections = Array.from(new Set(allPosts.map((p) => p.collection).filter(Boolean))).sort()
55
+
56
+ export default function ({ collectionTitles = {} } = {}) {
57
+ const currentCollection = signal('')
58
+ const activeCollection = onCondition(currentCollection)
59
+ const visibleCount = signal(10)
60
+ const collectionList = Object.keys(collectionTitles || {}).length
61
+ ? Object.keys(collectionTitles).sort()
62
+ : defaultCollections
63
+ const resolveLabel = (value) => collectionTitles?.[value] || value
64
+
65
+ if (typeof window !== 'undefined') {
66
+ const params = new URLSearchParams(window.location.search)
67
+ const col = params.get('collection')
68
+ if (col) currentCollection.value = col
69
+
70
+ window.addEventListener('popstate', () => {
71
+ const p = new URLSearchParams(window.location.search)
72
+ currentCollection.value = p.get('collection') || ''
73
+ })
74
+ }
75
+
76
+ const filteredPosts = $(() => {
77
+ const col = currentCollection.value
78
+ if (!col) return allPosts
79
+ return allPosts.filter((p) => p.collection === col)
80
+ })
81
+
82
+ const visiblePosts = $(() => filteredPosts.value.slice(0, visibleCount.value))
83
+ const hasMore = $(() => visibleCount.value < filteredPosts.value.length)
84
+ const showEmpty = $(() => filteredPosts.value.length === 0)
85
+
86
+ const loadMore = () => {
87
+ visibleCount.value += 10
88
+ }
89
+
90
+ const setCollection = (col) => {
91
+ currentCollection.value = col
92
+ visibleCount.value = 10
93
+ const url = new URL(window.location)
94
+ if (col) {
95
+ url.searchParams.set('collection', col)
96
+ } else {
97
+ url.searchParams.delete('collection')
98
+ }
99
+ window.history.pushState({}, '', url)
100
+ }
101
+
102
+ return (
103
+ <div class="category-view">
104
+ <div class="category-list">
105
+ <button class="category-tag" class:active={activeCollection('')} on:click={() => setCollection('')}>
106
+ All
107
+ </button>
108
+ <For entries={collectionList}>
109
+ {({ item: col }) => (
110
+ <button class="category-tag" class:active={activeCollection(col)} on:click={() => setCollection(col)}>
111
+ {resolveLabel(col)}
112
+ </button>
113
+ )}
114
+ </For>
115
+ </div>
116
+
117
+ <div class="post-list">
118
+ <For entries={visiblePosts}>
119
+ {({ item: p }) => {
120
+ const dateStr = formatDate(p.frontmatter?.date || p.stats?.createdAt)
121
+
122
+ return (
123
+ <article class="post-item">
124
+ <div class="post-meta">
125
+ {dateStr && <span class="post-date">{dateStr}</span>}
126
+ {p.collection && <span class="post-categories"> &middot; {resolveLabel(p.collection)}</span>}
127
+ </div>
128
+ <h2 class="post-item-title">
129
+ <a href={p.routeHref}>{p.title || 'Untitled'}</a>
130
+ </h2>
131
+ <div class="post-excerpt">{p.frontmatter.excerpt || p.excerpt || 'No excerpt available.'}</div>
132
+ </article>
133
+ )
134
+ }}
135
+ </For>
136
+ </div>
137
+
138
+ <If condition={showEmpty}>{() => <p>No posts found in this collection.</p>}</If>
139
+
140
+ <If condition={hasMore}>
141
+ {() => (
142
+ <div class="pagination-container">
143
+ <button class="load-more-btn" on:click={loadMore}>
144
+ Load More
145
+ </button>
146
+ </div>
147
+ )}
148
+ </If>
149
+ </div>
150
+ )
151
+ }
@@ -0,0 +1,37 @@
1
+ /* Copyright Yukino Song, SudoMaker Ltd.
2
+ *
3
+ * Licensed to the Apache Software Foundation (ASF) under one
4
+ * or more contributor license agreements. See the NOTICE file
5
+ * distributed with this work for additional information
6
+ * regarding copyright ownership. The ASF licenses this file
7
+ * to you under the Apache License, Version 2.0 (the
8
+ * "License"); you may not use this file except in compliance
9
+ * with the License. You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+
21
+ export default function ({ collectionTitles = {} } = {}, ...children) {
22
+ if (!children.length) return null
23
+ const resolveLabel = (value) => collectionTitles?.[value] || value
24
+ const collections = Object.keys(collectionTitles || {}).sort()
25
+ return (
26
+ <div class="category-view">
27
+ <div class="category-list">
28
+ <button class="category-tag active">All</button>
29
+ {collections.map((col) => (
30
+ <button class="category-tag">{resolveLabel(col)}</button>
31
+ ))}
32
+ </div>
33
+
34
+ <div class="post-list">{...children}</div>
35
+ </div>
36
+ )
37
+ }
@@ -0,0 +1,92 @@
1
+ /* Copyright Yukino Song, SudoMaker Ltd.
2
+ *
3
+ * Licensed to the Apache Software Foundation (ASF) under one
4
+ * or more contributor license agreements. See the NOTICE file
5
+ * distributed with this work for additional information
6
+ * regarding copyright ownership. The ASF licenses this file
7
+ * to you under the Apache License, Version 2.0 (the
8
+ * "License"); you may not use this file except in compliance
9
+ * with the License. You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+
21
+ import { signal, $, For, If } from 'refui'
22
+ import pages from 'methanol:pages'
23
+ import { formatDate } from '../src/date-utils.js'
24
+
25
+ const rawPages = Array.isArray(pages) ? pages : []
26
+ const isPostPage = (p) => {
27
+ if (!p?.routeHref) return false
28
+ if (p.routeHref === '/' || p.routeHref === '/404' || p.routeHref === '/offline') return false
29
+ if (p.routeHref.startsWith('/.methanol')) return false
30
+ return true
31
+ }
32
+ const resolvePosts = () => {
33
+ const list = rawPages.filter(isPostPage)
34
+ list.sort((a, b) => {
35
+ const dateA = new Date(a.frontmatter?.date || a.stats?.createdAt || 0)
36
+ const dateB = new Date(b.frontmatter?.date || b.stats?.createdAt || 0)
37
+ return dateB - dateA
38
+ })
39
+ return list.map((p) => ({
40
+ title: p.title,
41
+ routeHref: p.routeHref,
42
+ frontmatter: p.frontmatter || {},
43
+ stats: p.stats || {},
44
+ excerpt: p.excerpt || p.frontmatter?.excerpt || ''
45
+ }))
46
+ }
47
+ const allPosts = resolvePosts()
48
+
49
+ export default function ({ initialCount = 10 } = {}) {
50
+ const visibleCount = signal(initialCount)
51
+ const visiblePosts = $(() => allPosts.slice(0, visibleCount.value))
52
+ const hasMore = $(() => visibleCount.value < allPosts.length)
53
+ const showEmpty = $(() => allPosts.length === 0)
54
+
55
+ const loadMore = () => {
56
+ visibleCount.value += initialCount
57
+ }
58
+
59
+ return (
60
+ <div class="post-list-container">
61
+ <div class="post-list">
62
+ <For entries={visiblePosts}>
63
+ {({ item: p }) => {
64
+ const dateStr = formatDate(p.frontmatter?.date || p.stats?.createdAt)
65
+
66
+ return (
67
+ <article class="post-item">
68
+ <div class="post-meta">{dateStr && <span class="post-date">{dateStr}</span>}</div>
69
+ <h2 class="post-item-title">
70
+ <a href={p.routeHref}>{p.title || 'Untitled'}</a>
71
+ </h2>
72
+ <div class="post-excerpt">{p.excerpt || p.frontmatter.excerpt || 'No excerpt available.'}</div>
73
+ </article>
74
+ )
75
+ }}
76
+ </For>
77
+ </div>
78
+
79
+ <If condition={showEmpty}>{() => <p>No posts found.</p>}</If>
80
+
81
+ <If condition={hasMore}>
82
+ {() => (
83
+ <div class="pagination-container">
84
+ <button class="load-more-btn" on:click={loadMore}>
85
+ Load More
86
+ </button>
87
+ </div>
88
+ )}
89
+ </If>
90
+ </div>
91
+ )
92
+ }
@@ -0,0 +1,36 @@
1
+ /* Copyright Yukino Song, SudoMaker Ltd.
2
+ *
3
+ * Licensed to the Apache Software Foundation (ASF) under one
4
+ * or more contributor license agreements. See the NOTICE file
5
+ * distributed with this work for additional information
6
+ * regarding copyright ownership. The ASF licenses this file
7
+ * to you under the Apache License, Version 2.0 (the
8
+ * "License"); you may not use this file except in compliance
9
+ * with the License. You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+
21
+ export default function ({ hasMore = false } = {}, ...children) {
22
+ if (!children.length) return null
23
+ return (
24
+ <div class="post-list-container">
25
+ <div class="post-list">{...children}</div>
26
+
27
+ {hasMore && (
28
+ <div class="pagination-container">
29
+ <button class="load-more-btn" disabled>
30
+ Load More
31
+ </button>
32
+ </div>
33
+ )}
34
+ </div>
35
+ )
36
+ }