@tenjuu99/blog 0.1.0

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 (44) hide show
  1. package/.env.prod.sample +8 -0
  2. package/.env.sample +8 -0
  3. package/.github/workflows/deploy.yml.sample +51 -0
  4. package/.github/workflows/github-page.yml +47 -0
  5. package/.gitignore +9 -0
  6. package/README.md +145 -0
  7. package/generate.js +11 -0
  8. package/helper/add.js +3 -0
  9. package/helper/index.js +53 -0
  10. package/lib/applyTemplate.js +41 -0
  11. package/lib/cssGenerator.js +61 -0
  12. package/lib/dir.js +15 -0
  13. package/lib/distribute.js +35 -0
  14. package/lib/filter.js +167 -0
  15. package/lib/includeFilter.js +38 -0
  16. package/lib/indexer.js +82 -0
  17. package/lib/minify.js +22 -0
  18. package/lib/replaceIfFilter.js +67 -0
  19. package/lib/replaceScriptFilter.js +71 -0
  20. package/package.json +40 -0
  21. package/performance.js +22 -0
  22. package/server.js +48 -0
  23. package/src-sample/css/color.css +5 -0
  24. package/src-sample/css/layout.css +143 -0
  25. package/src-sample/css/markdown.css +49 -0
  26. package/src-sample/css/page.css +0 -0
  27. package/src-sample/css/reset.css +2 -0
  28. package/src-sample/helper/index.js +3 -0
  29. package/src-sample/image/.gitkeep +0 -0
  30. package/src-sample/pages/abc.md +5 -0
  31. package/src-sample/pages/fuga.md +3 -0
  32. package/src-sample/pages/hogehoge.md +8 -0
  33. package/src-sample/pages/html_render.html +20 -0
  34. package/src-sample/pages/index.md +35 -0
  35. package/src-sample/pages/notfound.md +8 -0
  36. package/src-sample/pages/rss.md +8 -0
  37. package/src-sample/pages/sample.md +145 -0
  38. package/src-sample/template/css.html +6 -0
  39. package/src-sample/template/default.html +55 -0
  40. package/src-sample/template/footer.html +7 -0
  41. package/src-sample/template/gtag.html +9 -0
  42. package/src-sample/template/index.html +24 -0
  43. package/src-sample/template/prevNext.html +35 -0
  44. package/src-sample/template/rss.xml +41 -0
@@ -0,0 +1,8 @@
1
+ ---
2
+ template: rss.xml
3
+ index: false
4
+ url: /rss
5
+ ext: xml
6
+ rss_description: ここにサイトの説明を入れてください。
7
+ rss_creator: test
8
+ ---
@@ -0,0 +1,145 @@
1
+ ---
2
+ title: sample article
3
+ url: /sample_article
4
+ published: 2024/03/18 00:00
5
+ modified: 2024/03/19 00:00
6
+ ifTrueVariable: true
7
+ someVariable: これは変数として定義された値です。変数定義を確認してください。
8
+ ---
9
+
10
+ トップレベル見出しは `title` 変数が利用されます。
11
+ 変えたい場合は template/default.html を修正してください。
12
+
13
+ ## サンプル記事
14
+
15
+ これはサンプル記事です。ブログ開始のときに削除してください。
16
+
17
+ ## マークダウン
18
+
19
+ 記事は、マークダウン記法で記述し、 `.md` ファイルで保存してください。
20
+
21
+ リンクは次のように記述します。
22
+ [アンカーテキストはこちら](http://example.com)
23
+
24
+ リストは次のように記述します。
25
+ * リスト1
26
+ * リスト2
27
+ * リスト3
28
+
29
+ 画像は、 `data/image/` 以下に配置して、パスを指定してください。
30
+
31
+ `data/image/sample.jpg` などがあれば、次の指定になります。
32
+ `![代替テキストを入力してください](/image/sample.jpg)`
33
+
34
+ ![placeholdの画像](https://placehold.jp/150x150.png)
35
+
36
+ ## テンプレートエンジン
37
+
38
+ if 文と script が使えます。
39
+
40
+ ### IF
41
+
42
+ if 文は次のような記述になります。
43
+
44
+ <pre>
45
+ ---
46
+ ifTrueVariable: true
47
+ ---
48
+ &lt;if ifTrueVariable>
49
+ `ifTrueVariable` が true のためこれは表示されます。
50
+ &lt;/if>
51
+ </pre>
52
+
53
+ 上記の出力は以下になります。
54
+
55
+ ```
56
+ <if ifTrueVariable>
57
+ `ifTrueVariable` が true のためこれは表示されます。
58
+ </if>
59
+ ```
60
+
61
+ else 句を含むことができます。
62
+
63
+ <pre>
64
+ &lt;if undefinedValue>
65
+ このコンテンツは表示されません
66
+ &lt;else>
67
+ これは else 文の中身です。
68
+ &lt;/if>
69
+ </pre>
70
+
71
+ 次のようになります。
72
+ ```
73
+ <if undefinedValue>
74
+ このコンテンツは表示されません
75
+ <else>
76
+ これは else 文の中身です。
77
+ </if>
78
+ ```
79
+
80
+ ### SCRIPT
81
+
82
+ スクリプトを記述することができます。
83
+
84
+ <pre>
85
+ &lt;script type="ssg"&gt;
86
+ return (new Date()).toString()
87
+ &lt;/script&gt;
88
+ </pre>
89
+
90
+ この出力は以下のようになります。このスクリプトではビルド時の時刻が刻まれます。ビルドしなおしてみてください。
91
+
92
+ ```
93
+ <script type="ssg">
94
+ return (new Date()).toString()
95
+ </script>
96
+ ```
97
+
98
+ スクリプトタグ内では、当該コメントで定義した変数が `variables.定義した変数名`で利用できます。
99
+
100
+ <pre>
101
+ ---
102
+ someVariable: これは変数として定義された値です。変数定義を確認してください。
103
+ ---
104
+ &lt;script type="ssg">
105
+ return variables.someVariable
106
+ &lt;/script>
107
+ </pre>
108
+
109
+ 以下のように出力されます。
110
+ ```
111
+ {script}
112
+ return variables.someVariable
113
+ {/script}
114
+ ```
115
+
116
+ ## 追加ヘルパー
117
+
118
+ ヘルパー関数を作成します。
119
+ ```
120
+ // src-sample/helper/index.js
121
+ export function additionalHelper() {
122
+ return 'これは追加ヘルパーによって出力されているメッセージです。'
123
+ }
124
+ ```
125
+
126
+ .env ファイルにヘルパーの位置を教えます。
127
+ ```
128
+ // .env
129
+ HELPER=helper/index.js
130
+ ```
131
+
132
+ 追加したヘルパーを利用できます。
133
+ <pre>
134
+ // src-sample/pages/sample.md
135
+ &lt;script type="ssg">
136
+ return helper.additionalHelper()
137
+ &lt;/script>
138
+ </pre>
139
+
140
+ 実際に出力させると次の行のとおりです。
141
+ ```
142
+ <script type="ssg">
143
+ return helper.additionalHelper()
144
+ </script>
145
+ ```
@@ -0,0 +1,6 @@
1
+ <style>
2
+ {include('css/reset.css')}
3
+ </style>
4
+ <link rel="stylesheet" href="${/css/layout.css<<layout.css,color.css}">
5
+ <link rel="preload" href="${/css/lazy.css<<page.css,markdown.css}" as="style">
6
+ <link rel="stylesheet" href="${/css/lazy.css<<page.css,markdown.css}" media="print" onload="this.media='all'">
@@ -0,0 +1,55 @@
1
+ <!DOCTYPE html>
2
+ <html lang="{{LANG}}">
3
+ <head prefix="og: http://ogp.me/ns#">
4
+ {if gtag_id}
5
+ {include('template/gtag.html')}
6
+ {/if}
7
+ <meta charset="UTF-8">
8
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
9
+ <title>{{TITLE}} | {{SITE_NAME}}</title>
10
+ {if noindex}
11
+ <meta name="robots" content="noindex" />
12
+ {/if}
13
+ <meta property="og:url" content="{{URL_BASE}}{{URL}}">
14
+ <meta property="og:title" content="{{TITLE}}">
15
+ {if og_image}
16
+ <meta property="og:image" content="{{OG_IMAGE}}">
17
+ {/if}
18
+ {if og_description}
19
+ <meta property="og:description" content="{{OG_DESCRIPTION}}">
20
+ {/if}
21
+ <meta property="og:type" content="article">
22
+ <meta property="og:site_name" content="{{SITE_NAME}}">
23
+ {script}
24
+ const url = variables.url_base + encodeURI(variables.url)
25
+ return `<link rel="canonical" href="${url}">`
26
+ {/script}
27
+ <meta name="description" content="{{DESCRIPTION}}">
28
+
29
+ {include('template/css.html')}
30
+ </head>
31
+ <body>
32
+ <header>
33
+ <p class="container"><a href="{{RELATIVE_PATH}}/">{{SITE_NAME}}</a></p>
34
+ </header>
35
+ <main>
36
+ <article class="container">
37
+ <h1>{{TITLE}}</h1>
38
+ {if published != '1970-01-01'}
39
+ <aside class="published">
40
+ <p>投稿: {script}return helper.dateFormat(variables.published){/script}
41
+ {/if}
42
+ {if modified} / 更新: {script}return helper.dateFormat(variables.modified){/script}{/if}
43
+ {if published}
44
+ </p>
45
+ </aside>
46
+ {/if}
47
+ {{MARKDOWN}}
48
+ </article>
49
+
50
+ {include('template/prevNext.html')}
51
+ </main>
52
+
53
+ {include('template/footer.html')}
54
+ </body>
55
+ </html>
@@ -0,0 +1,7 @@
1
+ <footer>
2
+ <ul class="container">
3
+ <li><a href="{{RELATIVE_PATH}}/about">about</a></li>
4
+ <li><a href="{{RELATIVE_PATH}}/privacy_policy">プライバシーポリシー</a></li>
5
+ <li><a href="{{RELATIVE_PATH}}/rss.xml">RSS</a></li>
6
+ </ul>
7
+ </footer>
@@ -0,0 +1,9 @@
1
+ <!-- Google tag (gtag.js) -->
2
+ <script async src="https://www.googletagmanager.com/gtag/js?id={{GTAG_ID}}"></script>
3
+ <script>
4
+ window.dataLayer = window.dataLayer || [];
5
+ function gtag(){dataLayer.push(arguments);}
6
+ gtag('js', new Date());
7
+
8
+ gtag('config', '{{GTAG_ID}}');
9
+ </script>
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html lang="ja">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>{{SITE_NAME}}</title>
7
+ {if gtag_id}
8
+ {include('template/gtag.html')}
9
+ {/if}
10
+ {include('template/css.html')}
11
+ </head>
12
+ <body>
13
+ <header>
14
+ <h1 class="container"><a href="{{RELATIVE_PATH}}/">{{SITE_NAME}}</a></h1>
15
+ </header>
16
+ <main>
17
+ <div class="container">
18
+ {{MARKDOWN}}
19
+ </div>
20
+ </main>
21
+
22
+ {include('template/footer.html')}
23
+ </body>
24
+ </html>
@@ -0,0 +1,35 @@
1
+ {script}
2
+ if (!variables.index) {
3
+ return ''
4
+ }
5
+ if (variables.published === '1970-01-01') {
6
+ return ''
7
+ }
8
+ const template = `
9
+ <div class="container">
10
+ <ul class="prevNext">
11
+ <li class="prevNext__prev">{{prev}}</li>
12
+ <li class="prevNext__next">{{next}}</li>
13
+ </ul>
14
+ </div>
15
+ `
16
+ const data = helper.readIndex().filter(v => v.published !== '1970-01-01' && v.index)
17
+
18
+ let prev = '', next = '', current = false
19
+ for (const page of data) {
20
+ const url = variables.relative_path ? variables.relative_path + page.url : page.url
21
+ if (current) {
22
+ prev = `<a href="${url}">${page.title}</a>`
23
+ break
24
+ }
25
+ if (variables.name === page.name) {
26
+ current = true
27
+ continue
28
+ }
29
+ next = `<a href="${url}">${page.title}</a>`
30
+ }
31
+ if (!next && !prev) return ''
32
+ variables.prev = prev
33
+ variables.next = next
34
+ return template
35
+ {/script}
@@ -0,0 +1,41 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <rss version="2.0"
3
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
4
+ xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
5
+ xmlns:admin="http://webns.net/mvcb/"
6
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
7
+
8
+ <channel>
9
+ <title>{{SITE_NAME}}</title>
10
+ <link>{{URL_BASE}}/rss</link>
11
+ <description>{{RSS_DESCRIPTION}}</description>
12
+ <dc:language>ja</dc:language>
13
+ <dc:creator>{{RSS_CREATOR}}</dc:creator>
14
+ {script}
15
+ const data = helper.readIndex()
16
+
17
+ let lastUpdatedAt = ''
18
+ let items = []
19
+ for (const page of data) {
20
+ if (page.index) {
21
+ const published = new Date(`${page.published} GMT+0900`)
22
+ if (!lastUpdatedAt) {
23
+ lastUpdatedAt = published
24
+ }
25
+ if (lastUpdatedAt.getTime() > published.getTime()) {
26
+ lastUpdatedAt = published
27
+ }
28
+ items.push(`
29
+ <item>
30
+ <title>${page.title}</title>
31
+ <link>{{URL_BASE}}${encodeURI(page.url)}</link>
32
+ <pubDate>${published.toUTCString()}</pubDate>
33
+ </item>
34
+ `)
35
+ }
36
+ }
37
+ items.unshift(`<dc:date>${lastUpdatedAt}</dc:date>\n`)
38
+ return items.join("\n")
39
+ {/script}
40
+ </channel>
41
+ </rss>