@compiiile/compiiile 2.22.0 → 2.22.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.
|
@@ -6,7 +6,20 @@ import SlidesLayout from "../layouts/SlidesLayout.astro"
|
|
|
6
6
|
import path from "node:path"
|
|
7
7
|
|
|
8
8
|
export async function getStaticPaths() {
|
|
9
|
-
|
|
9
|
+
// Literal patterns to exclude which matches `IGNORED_ENTRIES` from `Context.js`
|
|
10
|
+
const markdownFiles = Object.values(import.meta.glob([
|
|
11
|
+
'@source/**/*.{md,mdx}',
|
|
12
|
+
'!@source/**/.vuepress/**',
|
|
13
|
+
'!@source/**/.git/**',
|
|
14
|
+
'!@source/**/node_modules/**',
|
|
15
|
+
'!@source/**/.compiiile/**',
|
|
16
|
+
'!@source/**/bin/**',
|
|
17
|
+
'!@source/**/.idea/**',
|
|
18
|
+
'!@source/**/.DS_Store/**',
|
|
19
|
+
'!@source/**/.gitignore/**',
|
|
20
|
+
'!@source/**/var/**',
|
|
21
|
+
'!@source/**/vendor/**',
|
|
22
|
+
], { eager: true }))
|
|
10
23
|
|
|
11
24
|
return routeList.map(route => {
|
|
12
25
|
const md = markdownFiles.find(post => {
|
package/bin/config.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { build, dev, preview } from "astro"
|
|
2
2
|
import vue from "@astrojs/vue"
|
|
3
|
-
import { passthroughImageService } from "astro/config"
|
|
4
3
|
import compiiile from "./vitePluginCompiiile/index.js"
|
|
5
4
|
import mdx from "@astrojs/mdx"
|
|
6
5
|
import path from "node:path"
|
|
@@ -100,7 +99,9 @@ const astroConfig = {
|
|
|
100
99
|
enabled: false
|
|
101
100
|
},
|
|
102
101
|
image: {
|
|
103
|
-
service:
|
|
102
|
+
service: {
|
|
103
|
+
entrypoint: fileURLToPath(new URL("./passthroughImageService.js", import.meta.url))
|
|
104
|
+
}
|
|
104
105
|
},
|
|
105
106
|
...(configFromFile.astroConfig ?? {}),
|
|
106
107
|
...(argv.astroConfig ?? {})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
validateOptions(options) {
|
|
3
|
+
if (!options.format && typeof options.src === "object") {
|
|
4
|
+
options.format = options.src.format
|
|
5
|
+
}
|
|
6
|
+
return options
|
|
7
|
+
},
|
|
8
|
+
getURL(options) {
|
|
9
|
+
return typeof options.src === "string" ? options.src : options.src.src
|
|
10
|
+
},
|
|
11
|
+
parseURL(url) {
|
|
12
|
+
return { src: url.searchParams.get("href") }
|
|
13
|
+
},
|
|
14
|
+
getHTMLAttributes(options) {
|
|
15
|
+
const { src, format, quality, widths, densities, ...attrs } = options
|
|
16
|
+
return { ...attrs, loading: options.loading ?? "lazy", decoding: options.decoding ?? "async" }
|
|
17
|
+
},
|
|
18
|
+
async transform(inputBuffer, transformOptions) {
|
|
19
|
+
return { data: inputBuffer, format: transformOptions.format }
|
|
20
|
+
},
|
|
21
|
+
propertiesToHash: ["src"]
|
|
22
|
+
}
|
|
@@ -1,228 +1,230 @@
|
|
|
1
1
|
import path from "node:path"
|
|
2
2
|
import fs from "node:fs"
|
|
3
|
-
import {
|
|
3
|
+
import {v4 as uuidv4} from "uuid"
|
|
4
4
|
import FileListItem from "./FileListItem.js"
|
|
5
5
|
import FilesTreeItem from "./FilesTreeItem.js"
|
|
6
6
|
import RouteListItem from "./RouteListItem.js"
|
|
7
|
-
import {
|
|
8
|
-
import { remarkPlugins,
|
|
9
|
-
import {
|
|
7
|
+
import {createMarkdownProcessor} from "@astrojs/markdown-remark"
|
|
8
|
+
import {rehypePlugins, remarkPlugins, shikiConfig} from "../markdownConfig.js"
|
|
9
|
+
import {unemojify} from "node-emoji"
|
|
10
10
|
import slugify from "slugify"
|
|
11
11
|
import parseIgnore from "parse-gitignore"
|
|
12
|
-
import {
|
|
12
|
+
import {minimatch} from "minimatch"
|
|
13
13
|
|
|
14
14
|
export default class {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
15
|
+
WORKSPACE_BASE_PATH = "c"
|
|
16
|
+
SLIDES_BASE_PATH = "s"
|
|
17
|
+
|
|
18
|
+
constructor(directoryPath = ".") {
|
|
19
|
+
this.directoryPath = directoryPath
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async init() {
|
|
23
|
+
this.fileList = []
|
|
24
|
+
this.filesTree = []
|
|
25
|
+
this.routeList = []
|
|
26
|
+
this.fileRouteMap = {}
|
|
27
|
+
|
|
28
|
+
this.site = {
|
|
29
|
+
title: process.env.VITE_COMPIIILE_TITLE !== "" ? process.env.VITE_COMPIIILE_TITLE : undefined,
|
|
30
|
+
description:
|
|
31
|
+
process.env.VITE_COMPIIILE_DESCRIPTION !== "" ? process.env.VITE_COMPIIILE_DESCRIPTION : undefined,
|
|
32
|
+
logo: process.env.VITE_COMPIIILE_LOGO !== "null" ? process.env.VITE_COMPIIILE_LOGO : undefined,
|
|
33
|
+
logoUrl: process.env.VITE_COMPIIILE_LOGO_URL !== "" ? process.env.VITE_COMPIIILE_LOGO_URL : undefined,
|
|
34
|
+
siteUrl: process.env.VITE_COMPIIILE_SITE_URL !== "" ? process.env.VITE_COMPIIILE_SITE_URL : undefined,
|
|
35
|
+
base: process.env.VITE_COMPIIILE_BASE,
|
|
36
|
+
data: JSON.parse(process.env.VITE_COMPIIILE_DATA),
|
|
37
|
+
theme: process.env.VITE_COMPIIILE_THEME,
|
|
38
|
+
collapseFolders: JSON.parse(process.env.VITE_COMPIIILE_COLLAPSE_FOLDERS)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
this.filesTree = await this.scanDirectoryRecursively(this.directoryPath)
|
|
43
|
+
return this
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
generateRoutePathFromFilePath(filePath, hash = "", asSlides = false, entryFileMatcher) {
|
|
47
|
+
const filePathWithoutExtension = filePath.substring(0, filePath.lastIndexOf("."))
|
|
48
|
+
const sluggifiedPath = filePathWithoutExtension
|
|
49
|
+
.split("/")
|
|
50
|
+
.map((val) => slugify(val, {lower: true}))
|
|
51
|
+
.join("/")
|
|
52
|
+
|
|
53
|
+
if (sluggifiedPath.match(new RegExp(/^/.source + entryFileMatcher.source))) {
|
|
54
|
+
if (process.env.VITE_COMPIIILE_BASE !== "/") {
|
|
55
|
+
return process.env.VITE_COMPIIILE_BASE
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return "/"
|
|
59
|
+
}
|
|
60
|
+
return `${
|
|
61
|
+
process.env.VITE_COMPIIILE_BASE.endsWith("/")
|
|
62
|
+
? process.env.VITE_COMPIIILE_BASE.slice(0, -1)
|
|
63
|
+
: process.env.VITE_COMPIIILE_BASE
|
|
64
|
+
}/${asSlides ? this.SLIDES_BASE_PATH : this.WORKSPACE_BASE_PATH}/${sluggifiedPath}${hash}`
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getFileTitleFromProcessedMarkdown(processedMarkdown) {
|
|
68
|
+
let firstHeading = null
|
|
69
|
+
if (JSON.parse(process.env.VITE_COMPIIILE_USE_AUTO_TITLES) && processedMarkdown.metadata.headings.length > 0) {
|
|
70
|
+
let firstHeadingIndex = 0
|
|
71
|
+
if (Object.keys(processedMarkdown.metadata.frontmatter).length > 0) {
|
|
72
|
+
// If a frontmatter is set, it is present as the first index in the `headings` array
|
|
73
|
+
firstHeadingIndex = 1
|
|
74
|
+
}
|
|
75
|
+
// Remove the starting '#' from the title
|
|
76
|
+
firstHeading = processedMarkdown.metadata.headings[firstHeadingIndex]?.text?.slice(1)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return processedMarkdown.metadata.frontmatter.title || firstHeading
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
getEntryFileMatcher(files) {
|
|
83
|
+
return files.find((file) => file.toLowerCase().match(/^readme.mdx?$/)) ? /readme/ : /index/
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async scanDirectoryRecursively(directoryPath) {
|
|
87
|
+
const fileArray = []
|
|
88
|
+
|
|
89
|
+
const collator = new Intl.Collator(undefined, {
|
|
90
|
+
numeric: true,
|
|
91
|
+
sensitivity: "base"
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
const IGNORED_ENTRIES = new Set([
|
|
95
|
+
".vuepress",
|
|
96
|
+
".git",
|
|
97
|
+
"node_modules",
|
|
98
|
+
".compiiile",
|
|
99
|
+
"bin",
|
|
100
|
+
".idea",
|
|
101
|
+
".DS_Store",
|
|
102
|
+
".gitignore",
|
|
103
|
+
"var",
|
|
104
|
+
"vendor"
|
|
105
|
+
])
|
|
106
|
+
|
|
107
|
+
const files = fs.readdirSync(directoryPath)
|
|
108
|
+
.filter((file) => !IGNORED_ENTRIES.has(file))
|
|
109
|
+
.sort(collator.compare)
|
|
110
|
+
|
|
111
|
+
const entryFileMatcher = this.getEntryFileMatcher(files)
|
|
112
|
+
|
|
113
|
+
for (let file of files) {
|
|
114
|
+
const filePath = path.join(directoryPath, file)
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
const compiiileIgnoreFilePath = fs.readFileSync(
|
|
118
|
+
path.join(process.env.COMPIIILE_SOURCE, ".compiiileignore")
|
|
119
|
+
)
|
|
120
|
+
const compiiileIgnore = parseIgnore(compiiileIgnoreFilePath)
|
|
121
|
+
|
|
122
|
+
const ignoreGlobs = compiiileIgnore.globs().filter((globType) => globType.type === "ignore")
|
|
123
|
+
const ignorePatterns = ignoreGlobs.reduce((patterns, currentIgnoreGlobItem) => {
|
|
124
|
+
return [...patterns, ...currentIgnoreGlobItem.patterns]
|
|
125
|
+
}, [])
|
|
126
|
+
|
|
127
|
+
const isFilePathInIgnoredPatterns = ignorePatterns.some((pattern) => minimatch(filePath, pattern))
|
|
128
|
+
|
|
129
|
+
if (isFilePathInIgnoredPatterns) {
|
|
130
|
+
continue
|
|
131
|
+
}
|
|
132
|
+
} catch (_) {
|
|
133
|
+
// No .compiiileignore file found at the root
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const isDirectory = fs.statSync(filePath).isDirectory()
|
|
137
|
+
const uuid = uuidv4()
|
|
138
|
+
const fileName = path.parse(filePath).name
|
|
139
|
+
const isReadmeFile =
|
|
140
|
+
!isDirectory &&
|
|
141
|
+
filePath
|
|
142
|
+
.toLowerCase()
|
|
143
|
+
.match(new RegExp(/^(.*?\/?)/.source + entryFileMatcher.source + /\.mdx?$/.source))
|
|
144
|
+
|
|
145
|
+
let filesTreeItem = new FilesTreeItem(uuid, fileName)
|
|
146
|
+
|
|
147
|
+
if (isDirectory) {
|
|
148
|
+
filesTreeItem.isDirectory = true
|
|
149
|
+
filesTreeItem.children = await this.scanDirectoryRecursively(filePath)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (path.extname(file).match(/^\.mdx?$/) || filesTreeItem?.children.length > 0) {
|
|
153
|
+
if (isReadmeFile) {
|
|
154
|
+
fileArray.unshift(filesTreeItem)
|
|
155
|
+
} else {
|
|
156
|
+
fileArray.push(filesTreeItem)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (!isDirectory) {
|
|
160
|
+
const fileListItem = new FileListItem(uuid)
|
|
161
|
+
const markdownContent = fs.readFileSync(filePath, {
|
|
162
|
+
encoding: "utf8"
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
const markdownProcessor = await createMarkdownProcessor({
|
|
166
|
+
remarkPlugins,
|
|
167
|
+
rehypePlugins: rehypePlugins(this),
|
|
168
|
+
shikiConfig
|
|
169
|
+
})
|
|
170
|
+
const renderedMarkdown = await markdownProcessor.render(markdownContent)
|
|
171
|
+
|
|
172
|
+
fileListItem.textContent = unemojify(
|
|
173
|
+
renderedMarkdown.code
|
|
174
|
+
.replace(/^<hr>\n<h2(.|\n)*?<\/h2>/g, "")
|
|
175
|
+
.replace(/<br>/g, " ")
|
|
176
|
+
.replace(/<a.*aria-hidden.*>.*?<\/a>|<[^>]*>?/gi, "")
|
|
177
|
+
.replace(/[\r\n]{2,}/g, "\n")
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
const meta = renderedMarkdown.metadata.frontmatter
|
|
181
|
+
|
|
182
|
+
if (meta.ignore) {
|
|
183
|
+
const fileIndex = fileArray.findIndex((f) => f.uuid === fileListItem.uuid)
|
|
184
|
+
if (fileIndex > -1) {
|
|
185
|
+
fileArray.splice(fileIndex, 1)
|
|
186
|
+
}
|
|
187
|
+
continue
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const title = this.getFileTitleFromProcessedMarkdown(renderedMarkdown) || fileName
|
|
191
|
+
fileListItem.title = title
|
|
192
|
+
fileListItem.meta = meta
|
|
193
|
+
fileListItem.meta.title = title
|
|
194
|
+
fileListItem.fullPath = filePath
|
|
195
|
+
|
|
196
|
+
const routePath = this.generateRoutePathFromFilePath(
|
|
197
|
+
filePath,
|
|
198
|
+
"",
|
|
199
|
+
fileListItem.meta.asSlides,
|
|
200
|
+
entryFileMatcher
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
if (isReadmeFile) {
|
|
204
|
+
let newIndex = 0
|
|
205
|
+
|
|
206
|
+
if (directoryPath !== ".") {
|
|
207
|
+
newIndex = this.fileList.findIndex((f) => f.fullPath.startsWith(directoryPath))
|
|
208
|
+
if (newIndex < 0) {
|
|
209
|
+
newIndex = this.fileList.length
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
this.fileList.splice(newIndex, 0, fileListItem)
|
|
214
|
+
} else {
|
|
215
|
+
this.fileList.push(fileListItem)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// `asSlides` frontmatter param is passed via the meta
|
|
219
|
+
const routeListItem = new RouteListItem(routePath, uuid, fileName, filePath, fileListItem.meta)
|
|
220
|
+
fileListItem.routePath = routeListItem.path
|
|
221
|
+
this.fileRouteMap[filePath] = routeListItem.path
|
|
222
|
+
this.routeList.push(routeListItem)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return fileArray
|
|
229
|
+
}
|
|
228
230
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compiiile/compiiile",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.22.
|
|
4
|
+
"version": "2.22.2",
|
|
5
5
|
"description": "The most convenient way to render a folder containing markdown files. Previewing and searching markdown files has never been that easy.",
|
|
6
6
|
"author": "AlbanCrepel <alban.crepel@gmail.com>",
|
|
7
7
|
"license": "GPL-3.0-only",
|