vowel 0.6.0 → 0.6.1
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/package.json +2 -1
- package/plugins/markdown/index.js +45 -4
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.1",
|
|
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
|
|