@compiiile/compiiile 2.5.0 → 2.7.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.
package/README.md CHANGED
@@ -156,24 +156,25 @@ Other frontmatter keys are handled:
156
156
 
157
157
  ### Routing
158
158
 
159
- The home page of Compiiile (`/`) points to a `README.md` file located at the root of your folder.
159
+ The home page of Compiiile (`/`) points to a `README.md` file located at the root of your folder, or fallbacks to an `index.md` file.
160
160
 
161
161
  ## Custom configuration
162
162
 
163
163
  Here is the list of parameters that you can set to customize Compiiile (none are required):
164
164
 
165
- | Parameter | Type | Description |
166
- | ---------------------- | ---------- | ----------------------------------------------------------------------------------------------------------- |
167
- | `title` | `string` | The title to display on the top-left of the User Interface |
168
- | `description` | `string` | The description that is rendered by default for the SEO |
169
- | `logo` | `string` | The relative path of the logo to display in the TopBar and as favicon |
170
- | `logoUrl` | `string` | The url to go to when clicking on the logo, defaults to the home page if not set |
171
- | `dest` | `string` | The folder in which to build files, defaults to `./.compiiile/dist` |
172
- | `siteUrl` | `string` | The url of the website in production (without trailing slash), used for the SEO tag `og:image` |
173
- | `astroConfig` | `Object` | Override [default Astro config](https://docs.astro.build/en/reference/configuration-reference/) |
174
- | `data` | `Object` | An object with data to use in MDX files (check use case below) |
175
- | `theme` | `string` | The website theme, value can be : `auto` (default value: adapts to system preferences) \| `light` \| `dark` |
176
- | `vite.server.fs.allow` | `string[]` | Add local paths to vite's server fs allow list |
165
+ | Parameter | Type | Description |
166
+ | ---------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------- |
167
+ | `title` | `string` | The title to display on the top-left of the User Interface |
168
+ | `description` | `string` | The description that is rendered by default for the SEO |
169
+ | `logo` | `string` | The relative path of the logo to display in the TopBar and as favicon |
170
+ | `logoUrl` | `string` | The url to go to when clicking on the logo, defaults to the home page if not set |
171
+ | `dest` | `string` | The folder in which to build files, defaults to `./.compiiile/dist` |
172
+ | `siteUrl` | `string` | The url of the website in production (without trailing slash), used for the SEO tag `og:image` |
173
+ | `astroConfig` | `Object` | Override [default Astro config](https://docs.astro.build/en/reference/configuration-reference/) |
174
+ | `data` | `Object` | An object with data to use in MDX files (check use case below) |
175
+ | `theme` | `string` | The website theme, value can be : `auto` (default value: adapts to system preferences) \| `light` \| `dark` |
176
+ | `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` |
177
+ | `vite.server.fs.allow` | `string[]` | Add local paths to vite's server fs allow list |
177
178
 
178
179
  You can use these parameters in 2 ways:
179
180
 
package/bin/config.js CHANGED
@@ -53,6 +53,7 @@ process.env.VITE_COMPIIILE_LOGO_URL = argv.logoUrl ?? ""
53
53
  process.env.VITE_COMPIIILE_THEME = argv.theme ?? "auto"
54
54
 
55
55
  process.env.VITE_COMPIIILE_DATA = JSON.stringify(argv.data ?? {})
56
+ process.env.VITE_COMPIIILE_USE_AUTO_TITLES = /true/i.test(argv.useAutoTitles) // defaults to `false` if not set or not equal to `true`
56
57
 
57
58
  // Handling logo and favicon
58
59
  process.env.VITE_COMPIIILE_LOGO = null
@@ -32,14 +32,14 @@ export default class {
32
32
  }
33
33
  }
34
34
 
35
- generateRoutePathFromFilePath(filePath, hash = "", asSlides = false) {
35
+ generateRoutePathFromFilePath(filePath, hash = "", asSlides = false, entryFileMatcher) {
36
36
  const filePathWithoutExtension = filePath.substring(0, filePath.lastIndexOf("."))
37
37
  const sluggifiedPath = filePathWithoutExtension
38
38
  .split("/")
39
39
  .map((val) => slugify(val, { lower: true }))
40
40
  .join("/")
41
41
 
42
- if (sluggifiedPath === "readme") {
42
+ if (sluggifiedPath.match(entryFileMatcher)) {
43
43
  if (process.env.VITE_COMPIIILE_BASE !== "/") {
44
44
  return process.env.VITE_COMPIIILE_BASE
45
45
  }
@@ -63,6 +63,8 @@ export default class {
63
63
 
64
64
  const files = fs.readdirSync(directoryPath).sort(collator.compare)
65
65
 
66
+ const entryFileMatcher = files.find((file) => file.toLowerCase() === "readme.md") ? /readme/ : /index/
67
+
66
68
  for (let file of files) {
67
69
  if (
68
70
  ![
@@ -81,7 +83,9 @@ export default class {
81
83
  const isDirectory = fs.statSync(filePath).isDirectory()
82
84
  const uuid = uuidv4()
83
85
  const fileName = path.parse(filePath).name
84
- const isReadmeFile = !isDirectory && filePath.toLowerCase().match(/^readme\.mdx?$/)
86
+ const isReadmeFile =
87
+ !isDirectory &&
88
+ filePath.toLowerCase().match(new RegExp(/^/.source + entryFileMatcher.source + /\.mdx?$/.source))
85
89
 
86
90
  let filesTreeItem = new FilesTreeItem(uuid, fileName)
87
91
 
@@ -116,12 +120,31 @@ export default class {
116
120
 
117
121
  const meta = renderedMarkdown.metadata.frontmatter
118
122
 
119
- fileListItem.title = meta.title || fileName
123
+ let firstHeading = null
124
+ if (
125
+ JSON.parse(process.env.VITE_COMPIIILE_USE_AUTO_TITLES) &&
126
+ renderedMarkdown.metadata.headings.length > 0
127
+ ) {
128
+ let firstHeadingIndex = 0
129
+ if (Object.keys(renderedMarkdown.metadata.frontmatter).length > 0) {
130
+ // If a frontmatter is set, it is present as the first index in the `headings` array
131
+ firstHeadingIndex = 1
132
+ }
133
+ // Remove the starting '#' from the title
134
+ firstHeading = renderedMarkdown.metadata.headings[firstHeadingIndex]?.text?.slice(1)
135
+ }
136
+
137
+ fileListItem.title = meta.title || firstHeading || fileName
120
138
  fileListItem.meta = meta
121
139
  fileListItem.meta.title = fileListItem.meta.title || fileListItem.title
122
140
  fileListItem.fullPath = filePath
123
141
 
124
- const routePath = this.generateRoutePathFromFilePath(filePath, "", fileListItem.meta.asSlides)
142
+ const routePath = this.generateRoutePathFromFilePath(
143
+ filePath,
144
+ "",
145
+ fileListItem.meta.asSlides,
146
+ entryFileMatcher
147
+ )
125
148
 
126
149
  if (isReadmeFile) {
127
150
  this.fileList.unshift(fileListItem)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@compiiile/compiiile",
3
3
  "private": false,
4
- "version": "2.5.0",
4
+ "version": "2.7.0",
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",