Merge pull request #15 from curbengh/basename

feat: disable basename globbing when pattern contains slash
This commit is contained in:
curbengh 2019-08-06 11:36:11 +09:30 committed by GitHub
commit 4923f5c39d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 6 deletions

View File

@ -17,7 +17,7 @@ if (hexo.config.neat_enable === true) {
removeStyleLinkTypeAttributes: true, removeStyleLinkTypeAttributes: true,
minifyJS: true, minifyJS: true,
minifyCSS: true, minifyCSS: true,
globOptions: { matchBase: true } globOptions: { basename: true }
}, hexo.config.neat_html) }, hexo.config.neat_html)
// CSS minifier // CSS minifier
@ -26,7 +26,7 @@ if (hexo.config.neat_enable === true) {
logger: false, logger: false,
exclude: ['*.min.css'], exclude: ['*.min.css'],
level: 2, level: 2,
globOptions: { matchBase: true } globOptions: { basename: true }
}, hexo.config.neat_css) }, hexo.config.neat_css)
// Javascript minifier // Javascript minifier
@ -37,7 +37,7 @@ if (hexo.config.neat_enable === true) {
compress: {}, compress: {},
mangle: true, mangle: true,
output: {}, output: {},
globOptions: { matchBase: true } globOptions: { basename: true }
}, hexo.config.neat_js) }, hexo.config.neat_js)
// SVG minifier // SVG minifier
@ -46,7 +46,7 @@ if (hexo.config.neat_enable === true) {
logger: false, logger: false,
include: ['*.svg', '!*.min.svg'], include: ['*.svg', '!*.min.svg'],
plugins: [], plugins: [],
globOptions: { matchBase: true } globOptions: { basename: true }
}, hexo.config.neat_svg) }, hexo.config.neat_svg)
// gzip compression // gzip compression
@ -54,7 +54,7 @@ if (hexo.config.neat_enable === true) {
enable: true, enable: true,
logger: false, logger: false,
include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json'], include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json'],
globOptions: { matchBase: true } globOptions: { basename: true }
}, hexo.config.neat_gzip) }, hexo.config.neat_gzip)
// brotli compression // brotli compression
@ -62,7 +62,7 @@ if (hexo.config.neat_enable === true) {
enable: true, enable: true,
logger: false, logger: false,
include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json'], include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json'],
globOptions: { matchBase: true } globOptions: { basename: true }
}, hexo.config.neat_brotli) }, hexo.config.neat_brotli)
const filter = require('./lib/filter') const filter = require('./lib/filter')

View File

@ -26,6 +26,10 @@ function logicHtml (str, data) {
const exclude = options.exclude const exclude = options.exclude
const globOptions = options.globOptions const globOptions = options.globOptions
let excludeString = exclude
if (Array.isArray(exclude)) excludeString = exclude.join('')
if (excludeString.includes('/')) globOptions.basename = false
// Return if a path matches exclusion pattern // Return if a path matches exclusion pattern
if (isMatch(path, exclude, globOptions)) return str if (isMatch(path, exclude, globOptions)) return str
@ -47,6 +51,10 @@ function logicCss (str, data) {
const exclude = options.exclude const exclude = options.exclude
const globOptions = options.globOptions const globOptions = options.globOptions
let excludeString = exclude
if (exclude && Array.isArray(exclude)) excludeString = exclude.join('')
if (excludeString && excludeString.includes('/')) globOptions.basename = false
if (isMatch(path, exclude, globOptions)) return str if (isMatch(path, exclude, globOptions)) return str
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -71,6 +79,10 @@ function logicJs (str, data) {
const exclude = options.exclude const exclude = options.exclude
const globOptions = options.globOptions const globOptions = options.globOptions
let excludeString = exclude
if (exclude && Array.isArray(exclude)) excludeString = exclude.join('')
if (excludeString && excludeString.includes('/')) globOptions.basename = false
if (isMatch(path, exclude, globOptions)) return str if (isMatch(path, exclude, globOptions)) return str
// Terser doesn't like unsupported options // Terser doesn't like unsupported options
@ -100,6 +112,10 @@ function logicSvg () {
let include = options.include let include = options.include
const globOptions = options.globOptions const globOptions = options.globOptions
let includeString = include
if (include && Array.isArray(include)) includeString = include.join('')
if (includeString && includeString.includes('/')) globOptions.basename = false
return Promise.all((micromatch(routeList, include, globOptions)).map(path => { return Promise.all((micromatch(routeList, include, globOptions)).map(path => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// Grab all assets using hexo router // Grab all assets using hexo router
@ -138,6 +154,10 @@ function logicGzip () {
let include = options.include let include = options.include
const globOptions = options.globOptions const globOptions = options.globOptions
let includeString = include
if (include && Array.isArray(include)) includeString = include.join('')
if (includeString && includeString.includes('/')) globOptions.basename = false
return Promise.all((micromatch(routeList, include, globOptions)).map(path => { return Promise.all((micromatch(routeList, include, globOptions)).map(path => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// Grab all assets using hexo router // Grab all assets using hexo router
@ -180,6 +200,10 @@ function logicBrotli () {
let include = options.include let include = options.include
const globOptions = options.globOptions const globOptions = options.globOptions
let includeString = include
if (include && Array.isArray(include)) includeString = include.join('')
if (includeString && includeString.includes('/')) globOptions.basename = false
return Promise.all((micromatch(routeList, include, globOptions)).map(path => { return Promise.all((micromatch(routeList, include, globOptions)).map(path => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// Grab all assets using hexo router // Grab all assets using hexo router