Skip to content

Commit

Permalink
Merge pull request #1193 from kethinov/0.21.5
Browse files Browse the repository at this point in the history
0.21.5
  • Loading branch information
kethinov authored Aug 16, 2022
2 parents 2e7d094 + ee10f0d commit 0e3ab9c
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 48 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

- Put your changes here...

## 0.21.5

- `allowlist` and `blocklist` in static site generator feature now supports wildcard matching, e.g. `dir/*`.
- Various dependencies updated.

## 0.21.4

- Added `allowlist` and `blocklist` to the static site generator feature.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ Resolves to:
- `sourcePath`: Subdirectory within `staticsRoot` where your static HTML files are located. By default this folder will not be made public, but is instead meant to store unminified / unprocessed HTML template source files which will be rendered, minified, and written to the `public` folder when the app is started.
- `allowlist`: *[Array]* of *[Strings]* List of templates to render, minify, and write to the `public` folder when the app is started. If the list is empty, all templates in your `sourcePath` will be sourced.
- `allowlist`: *[Array]* of *[Strings]* List of templates to render, minify, and write to the `public` folder when the app is started. If the list is empty, all templates in your `sourcePath` will be sourced. Supports wildcard matching, e.g. `dir/*`.
- `blocklist`: *[Array]* of *[Strings]* List of templates in your `sourcePath` to skip.
- `blocklist`: *[Array]* of *[Strings]* List of templates in your `sourcePath` to skip. Supports wildcard matching, e.g. `dir/*`.
- `models`: Data to pass to templates by file path / file name.
- Example:
Expand Down
3 changes: 2 additions & 1 deletion lib/preprocessStaticPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = (app, callback) => {
const minifyOptions = app.get('params').html.minifier.options
const logger = app.get('logger')
const fsr = require('./tools/fsr')(app)
const wildcardMatch = require('./tools/wildcardMatch')
const promises = []
const gitignoreFiles = gitignoreScanner(path.join(app.get('appDir'), '.gitignore'))
const allowlist = app.get('params').html.allowlist
Expand Down Expand Up @@ -53,7 +54,7 @@ module.exports = (app, callback) => {
(async () => {
try {
const baseFile = file.replace(app.get('params').html.sourcePath + '/', '')
if ((allowlist && allowlist.length > 0 && !allowlist.includes(baseFile)) || (blocklist && blocklist.length > 0 && blocklist.includes(baseFile))) {
if ((allowlist && allowlist.length > 0 && !wildcardMatch(baseFile, allowlist)) || (blocklist && blocklist.length > 0 && wildcardMatch(baseFile, blocklist))) {
// skip this file if it's not on the allowlist
// but only if an allowlist exists
// also skip it if it's on the blocklist
Expand Down
47 changes: 47 additions & 0 deletions lib/tools/wildcardMatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
check if a string matches a wildcard string
arguments:
- str: string
- matchList: string or array of strings
e.g.
example rule to match: "dir/*"
valid strings:
- "dir/foo" => true
- "dir/bar" => true
- "foo" => false
- "bar/foo" => false
*/

const path = require('path')

module.exports = (str, matchList) => {
if (typeof matchList === 'string') {
matchList = [matchList]
}
for (let rule of matchList) {
rule = path.normalize(rule).replace(/\\/g, '/') // normalize windows; including normalizing the slashes

// for this solution to work on any string, no matter what characters it has
const escapeRegex = (str) => str.replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1')

// "." => find a single character, except newline or line terminator
// ".*" => matches any string that contains zero or more characters
rule = rule.split('*').map(escapeRegex).join('.*')

// "^" => matches any string with the following at the beginning of it
// "$" => matches any string with that in front at the end of it
rule = '^' + rule + '$'

// create a regular expression object for matching string
const regex = new RegExp(rule)

// returns true if it finds a match, otherwise it returns false
if (regex.test(str)) {
return true
}
}

return false
}
86 changes: 43 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://github.com/rooseveltframework/roosevelt/graphs/contributors"
}
],
"version": "0.21.4",
"version": "0.21.5",
"files": [
"defaultErrorPages",
"lib",
Expand Down Expand Up @@ -54,7 +54,7 @@
"devDependencies": {
"c8": "~7.12.0",
"codecov": "~3.8.3",
"eslint": "~8.21.0",
"eslint": "~8.22.0",
"eslint-plugin-mocha": "~10.1.0",
"less": "~4.1.3",
"mocha": "~10.0.0",
Expand Down

0 comments on commit 0e3ab9c

Please sign in to comment.