Skip to content

Commit

Permalink
feat: dirs can be omitted from the url by using parenthesis. Example …
Browse files Browse the repository at this point in the history
…(dashboard)/home -> /home
  • Loading branch information
jakobrosenberg committed Nov 12, 2024
1 parent da6bf45 commit 3050080
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/buildtime/RoutifyBuildtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { createParallelHooksCollection } from 'hookar'
import { devHelperPlugin } from './plugins/devHelper/helper.js'
import { metaCapturePlugin } from './plugins/metaCapture/index.js'
import { log, logs } from './logMsgs.js'
import { omitDirFromPathPlugin } from './plugins/omitFromPath/index.js'

/** @returns {Partial<RoutifyBuildtimeOptions>} */
const getDefaults = () => ({
Expand Down Expand Up @@ -46,6 +47,7 @@ const getDefaults = () => ({
watcherPlugin,
devHelperPlugin,
metaCapturePlugin,
omitDirFromPathPlugin,
],
watch: false,
})
Expand Down
18 changes: 18 additions & 0 deletions lib/buildtime/plugins/omitFromPath/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** @type {RoutifyBuildtimePlugin} */
export const omitDirFromPathPlugin = {
name: 'omitDirFromPath',
after: 'filemapper',
before: 'bundler',
build: ({ instance }) => {
// find file names that are enclosed in a parenthesis
const omittedDir = node => node.file.name.match(/\(([^)]+)\)/)

// remove the node and move its children to the parent
instance.nodeIndex.filter(omittedDir).forEach(node => {
node.children.forEach(child => {
child.parent = node.parent
node.remove()
})
})
},
}

0 comments on commit 3050080

Please sign in to comment.