vowel 0.6.0 → 0.6.2
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.
- package/README.md +2 -2
- package/package.json +2 -1
- package/plugins/markdown/index.js +55 -5
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ See the docs: [vowel.cc](https://vowel.cc).
|
|
|
12
12
|
### Launch checklist
|
|
13
13
|
|
|
14
14
|
- [x] CLI
|
|
15
|
-
- [
|
|
15
|
+
- [x] Docs
|
|
16
16
|
- [x] Classes
|
|
17
17
|
- [x] Route patterns
|
|
18
18
|
- [x] Post list metadata
|
|
@@ -40,7 +40,7 @@ See the docs: [vowel.cc](https://vowel.cc).
|
|
|
40
40
|
- [x] Robots.txt
|
|
41
41
|
- [x] Sitemap.xml
|
|
42
42
|
- [x] RSS
|
|
43
|
-
- [
|
|
43
|
+
- [ ] 404.html (just make 404.md)
|
|
44
44
|
- [ ] Markup
|
|
45
45
|
- [.] Image as figure
|
|
46
46
|
- [x] Admonitions
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vowel",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.2",
|
|
5
5
|
"bin": "bin.js",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"unist-util-stringify-position": "^4.0.0",
|
|
68
68
|
"unist-util-visit": "^5.0.0",
|
|
69
69
|
"unist-util-visit-parents": "^6.0.0",
|
|
70
|
+
"unpic": "^4.2.2",
|
|
70
71
|
"url-metadata": "^5.4.1",
|
|
71
72
|
"voot": "^0.1.0",
|
|
72
73
|
"votive": "^0.4.0",
|
|
@@ -19,7 +19,7 @@ import { h } from 'hastscript'
|
|
|
19
19
|
import { normalizeHeadings } from 'mdast-normalize-headings'
|
|
20
20
|
import { readFileSync } from "fs"
|
|
21
21
|
import { remove } from "unist-util-remove"
|
|
22
|
-
import { testURL, testHashtags, createHashtagPage, toTitleCase, hashtagRegexSingle, createImagePaths, imageSizes } from "./../../utils.js"
|
|
22
|
+
import { testURL, testHashtags, createHashtagPage, toTitleCase, hashtagRegexSingle, createImagePaths, imageSizes, imageExts } from "./../../utils.js"
|
|
23
23
|
import { toHast } from 'mdast-util-to-hast'
|
|
24
24
|
import { toString as hastToString } from 'hast-util-to-string'
|
|
25
25
|
import { toString as mdastToString } from 'mdast-util-to-string'
|
|
@@ -27,6 +27,7 @@ import { unified } from "unified"
|
|
|
27
27
|
import { visit } from "unist-util-visit"
|
|
28
28
|
import toc from "@jsdevtools/rehype-toc"
|
|
29
29
|
import slug from "rehype-slug"
|
|
30
|
+
import * as unpic from "unpic"
|
|
30
31
|
|
|
31
32
|
const VOWEL_DIR = path.normalize(path.join(import.meta.dirname, "../../"))
|
|
32
33
|
|
|
@@ -57,10 +58,50 @@ Disallow: /`
|
|
|
57
58
|
* @param {string} dependent
|
|
58
59
|
*/
|
|
59
60
|
function createDynamicImage(imagePath, database, dependent, alt, itemprop) {
|
|
60
|
-
|
|
61
|
+
// TODO: Hardcode image height and width
|
|
62
|
+
const parsed = path.parse(imagePath);
|
|
63
|
+
const isURL = testURL(imagePath)
|
|
64
|
+
const isImg = !parsed.ext.search(/^.(png|jpeg|jpg)$/);
|
|
65
|
+
|
|
66
|
+
if (isURL) {
|
|
67
|
+
const parsedImageURL = unpic.parseUrl(imagePath)
|
|
68
|
+
if (parsedImageURL) {
|
|
69
|
+
|
|
70
|
+
const sources = [...imageExts, "jpeg"].map((format, index) => {
|
|
71
|
+
|
|
72
|
+
const isImg = index === imageExts.length
|
|
73
|
+
// TODO: Ignore images that have options already specified
|
|
74
|
+
const urls = imageSizes.map(size => {
|
|
75
|
+
return unpic.transformUrl({
|
|
76
|
+
format: format,
|
|
77
|
+
url: parsedImageURL.src,
|
|
78
|
+
provider: parsedImageURL.cdn,
|
|
79
|
+
width: size
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const sizes = urls.map((url, index) => `${url} ${imageSizes[index]}w`).join(", ")
|
|
84
|
+
|
|
85
|
+
return h(isImg ? "img" : "source", {
|
|
86
|
+
type: "image/" + format,
|
|
87
|
+
srcset: sizes,
|
|
88
|
+
src: isImg && urls.at(-1),
|
|
89
|
+
loading: isImg && "lazy",
|
|
90
|
+
sizes: "100vw",
|
|
91
|
+
alt: isImg && alt
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
return h("picture", { itemprop: itemprop && "image" }, sources)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!isImg) return
|
|
100
|
+
|
|
61
101
|
const relativePath = imagePath.startsWith("/") ? path.relative("/", imagePath) : imagePath
|
|
62
102
|
const image = database.target.getWithTrackers(relativePath, dependent)
|
|
63
|
-
console.log({
|
|
103
|
+
console.log({ image, relativePath })
|
|
104
|
+
if (!image) return
|
|
64
105
|
const formats = createImagePaths(image.abstract.sourcePath, "./", image.abstract.uuid)
|
|
65
106
|
|
|
66
107
|
|
|
@@ -79,7 +120,7 @@ function createDynamicImage(imagePath, database, dependent, alt, itemprop) {
|
|
|
79
120
|
})
|
|
80
121
|
})
|
|
81
122
|
|
|
82
|
-
|
|
123
|
+
|
|
83
124
|
return h("picture", { itemprop: itemprop && "image" }, sources)
|
|
84
125
|
}
|
|
85
126
|
|
|
@@ -1031,7 +1072,16 @@ function writeFile(destination, database, config) {
|
|
|
1031
1072
|
|
|
1032
1073
|
visit(treeContent, { tagName: "img" }, (node, index, parent) => {
|
|
1033
1074
|
const { src, alt } = node.properties
|
|
1034
|
-
|
|
1075
|
+
const image = createDynamicImage(src, database, destination.path.path, alt)
|
|
1076
|
+
if (index === 0 && parent.children.length > 1) {
|
|
1077
|
+
console.log(parent.children)
|
|
1078
|
+
const [_, ...caption] = parent.children
|
|
1079
|
+
parent.children = [
|
|
1080
|
+
h("figure", [image, h("figcaption", caption)])
|
|
1081
|
+
]
|
|
1082
|
+
} else {
|
|
1083
|
+
parent.children.splice(index, 1, image)
|
|
1084
|
+
}
|
|
1035
1085
|
})
|
|
1036
1086
|
|
|
1037
1087
|
visit(treeContent, testPaths, ({ children: [child] }, i, p) => {
|