@compiiile/compiiile 2.10.2 → 2.11.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.
@@ -0,0 +1,5 @@
1
+ {
2
+ "_variables": {
3
+ "lastUpdateCheck": 1718726455618
4
+ }
5
+ }
package/README.md CHANGED
@@ -207,6 +207,7 @@ Here is the list of parameters that you can set to customize Compiiile (none are
207
207
  | `theme` | `string` | The website theme, value can be : `auto` (default value: adapts to system preferences) \| `light` \| `dark` |
208
208
  | `useAutoTitles` | `Boolean` | If set to `true`, use the first file heading as title to be displayed in the navbar and for SEO. Defaults to `false` |
209
209
  | `noIndex` | `Boolean` | If set to `true`, the `robots.txt` file will disallow all routes, preventing indexation. Defaults to `false` |
210
+ | `publicDir` | `string` | The folder name in which you can serve public files, defaults to `public` |
210
211
  | `vite.server.fs.allow` | `string[]` | Add local paths to vite's server fs allow list |
211
212
 
212
213
  You can use these parameters in 2 ways:
@@ -238,6 +239,17 @@ export default {
238
239
 
239
240
  > ⚠️ You should bear in mind that script arguments have priority over config file parameters.
240
241
 
242
+ ## Public files
243
+
244
+ If you want some files to be public, just create a folder named `public` at the root of your Compiiile folder.
245
+
246
+ For example, if you want to link to a local PDF in your Markdown file, you can put your PDF in your local public directory, in `public/my-pdf.pdf`.
247
+ Then, all you have to do is creating a link in Markdown with an absolute path like so :
248
+
249
+ ```markdown
250
+ [Check the PDF](/my-pdf.pdf)
251
+ ```
252
+
241
253
  ## Use MDX
242
254
 
243
255
  v2 of Compiiile allows you to use MDX files with Vue components.
package/bin/config.js CHANGED
@@ -4,7 +4,7 @@ import { passthroughImageService } from "astro/config"
4
4
  import compiiile from "./vitePluginCompiiile/index.js"
5
5
  import mdx from "@astrojs/mdx"
6
6
  import path from "node:path"
7
- import { copyFileSync, cpSync } from "node:fs"
7
+ import { copyFileSync, cpSync, existsSync } from "node:fs"
8
8
  import { fileURLToPath } from "node:url"
9
9
  import markdownConfig from "./vitePluginCompiiile/markdownConfig.js"
10
10
  import resolvePackagePath from "resolve-package-path"
@@ -88,6 +88,9 @@ const argv = yargs(hideBin(process.argv))
88
88
  describe:
89
89
  "If set to `true`, the `robots.txt` file will disallow all routes, preventing indexation. Defaults to `false`"
90
90
  })
91
+ .option("publicDir", {
92
+ describe: "The folder name in which you can serve public files, defaults to `public`"
93
+ })
91
94
  .option("vite.server.fs.allow", {
92
95
  describe: "Add local paths to vite's server fs allow list"
93
96
  })
@@ -107,14 +110,41 @@ process.env.VITE_COMPIIILE_THEME = argv.theme ?? "auto"
107
110
  process.env.VITE_COMPIIILE_DATA = JSON.stringify(argv.data ?? {})
108
111
  process.env.VITE_COMPIIILE_USE_AUTO_TITLES = /true/i.test(argv.useAutoTitles) // defaults to `false` if not set or not equal to `true`
109
112
 
113
+
114
+ // Get command and set env
115
+ const IS_DEV = argv._.length === 0 || argv._.includes("dev")
116
+ const IS_BUILD = argv._.includes("build")
117
+ const IS_PREVIEW = argv._.includes("preview")
118
+
119
+ const NODE_ENV_DEVELOPMENT = "development"
120
+ const NODE_ENV_PRODUCTION = "production"
121
+ if (IS_DEV) {
122
+ process.env.NODE_ENV = NODE_ENV_DEVELOPMENT
123
+ } else if (IS_BUILD || IS_PREVIEW) {
124
+ process.env.NODE_ENV = NODE_ENV_PRODUCTION
125
+ }
126
+
127
+
110
128
  // Handling logo and favicon
111
129
  process.env.VITE_COMPIIILE_LOGO = null
112
130
 
113
131
  const publicDir = path.resolve(source, "./.compiiile/public")
114
132
 
133
+ const localPublicDirName = argv.publicDir ?? "public"
134
+ const localPublicDir = path.resolve(source, localPublicDirName)
135
+ const localPublicDirExists = existsSync(localPublicDir)
136
+
137
+ const hasPublicFiles = localPublicDirExists || argv.logo
138
+ if (hasPublicFiles) {
139
+ cpSync(fileURLToPath(new URL("../.compiiile/public", import.meta.url)), publicDir, { recursive: true })
140
+ }
141
+
142
+ if (localPublicDirExists) {
143
+ cpSync(localPublicDir, publicDir, { recursive: true })
144
+ }
145
+
115
146
  if (argv.logo) {
116
147
  try {
117
- cpSync(fileURLToPath(new URL("../.compiiile/public", import.meta.url)), publicDir, { recursive: true })
118
148
  copyFileSync(path.resolve(source, argv.logo), path.resolve(publicDir, "favicon.png"))
119
149
  // Set the logo to be displayed on the top bar if we were able to copy
120
150
  process.env.VITE_COMPIIILE_LOGO = argv.logo
@@ -139,7 +169,10 @@ const resolve = (mod) => {
139
169
  const resolvedModule = requireg.resolve("vue")
140
170
  const packagePath = resolvePackagePath(mod, resolvedModule)
141
171
  // Check to work on both Windows (using `\`) and UNIX systems (using `/`)
142
- return packagePath.slice(0, packagePath.lastIndexOf("/") < 0 ? packagePath.lastIndexOf("\\") : packagePath.lastIndexOf("/"))
172
+ return packagePath.slice(
173
+ 0,
174
+ packagePath.lastIndexOf("/") < 0 ? packagePath.lastIndexOf("\\") : packagePath.lastIndexOf("/")
175
+ )
143
176
  }
144
177
 
145
178
  const astroConfig = {
@@ -150,7 +183,7 @@ const astroConfig = {
150
183
  root: fileURLToPath(new URL("../.compiiile", import.meta.url)),
151
184
  srcDir: fileURLToPath(new URL("../.compiiile/src", import.meta.url)),
152
185
  outDir: path.join(source, argv.dest || ".compiiile/dist"),
153
- ...(argv.logo ? { publicDir } : {}),
186
+ ...(hasPublicFiles ? { publicDir } : {}),
154
187
  integrations: [
155
188
  vue({ appEntrypoint: "/src/app.js" }),
156
189
  ...(configFromFile.integrations ?? []),
@@ -172,7 +205,8 @@ const astroConfig = {
172
205
  kleur: resolve("kleur"),
173
206
  clsx: resolve("clsx"),
174
207
  "html-escaper": resolve("html-escaper"),
175
- cssesc: resolve("cssesc"),
208
+ ...(process.env.NODE_ENV === NODE_ENV_PRODUCTION ? {cssesc: resolve("cssesc")} : {}), // Not included in dev because of the 'module is not defined' error otherwise
209
+ mrmime: resolve("mrmime"),
176
210
  "@vue/reactivity": resolve("@vue/reactivity"),
177
211
  "@vue/shared": resolve("@vue/shared"),
178
212
  fzf: resolve("fzf"),
@@ -204,25 +238,13 @@ if (process.env.VITE_COMPIIILE_BASE !== "/" && process.env.VITE_COMPIIILE_BASE.e
204
238
  }
205
239
 
206
240
  const run = async (astroConfig) => {
207
- const IS_DEV = argv._.length === 0 || argv._.includes("dev")
208
- const IS_BUILD = argv._.includes("build")
209
- const IS_PREVIEW = argv._.includes("preview")
210
-
211
- const NODE_ENV_DEVELOPMENT = "development"
212
- const NODE_ENV_PRODUCTION = "production"
213
241
  if (IS_DEV) {
214
- process.env.NODE_ENV = NODE_ENV_DEVELOPMENT
215
-
216
242
  const devServer = await dev(astroConfig)
217
243
  devServer.watcher.add([source])
218
244
  return devServer
219
245
  } else if (IS_BUILD) {
220
- process.env.NODE_ENV = NODE_ENV_PRODUCTION
221
-
222
246
  return await build(astroConfig)
223
247
  } else if (IS_PREVIEW) {
224
- process.env.NODE_ENV = NODE_ENV_PRODUCTION
225
-
226
248
  return await preview(astroConfig)
227
249
  }
228
250
  }