-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: closes #69 and & adds sitemap: false option to pages #70
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
COMPONENT_OPTIONS_BLOCK: 'script', | ||
COMPONENT_OPTIONS_KEY: 'sitemap' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be customisable, you can set that key in the sitemap configuration in |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const { readFileSync } = require('fs') | ||
|
||
const acorn = require('acorn') | ||
const dynamicImport = require('acorn-dynamic-import') | ||
const inject = require('acorn-dynamic-import/lib/walk') | ||
const walker = inject.default(require('acorn-walk')) | ||
// Must not be an explicit dependency to avoid version mismatch issue. | ||
// See https://github.com/nuxt-community/nuxt-i18n/issues/297 | ||
const compiler = require('vue-template-compiler') | ||
// const { COMPONENT_OPTIONS_BLOCK, COMPONENT_OPTIONS_KEY } = require('constants') | ||
|
||
function extractComponentOptions (path, blockName, key) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should rename the function and file from |
||
let extractedData = key ? '' : {} | ||
let Component = compiler.parseComponent(readFileSync(path).toString()) | ||
const block = | ||
Component[blockName] || | ||
Component.customBlocks.find(block => block.type === blockName) | ||
if (!block || block.content.length < 1) { | ||
return extractedData | ||
} | ||
const parsed = acorn.Parser.extend(dynamicImport.default).parse( | ||
block.content, | ||
{ | ||
ecmaVersion: 10, | ||
sourceType: 'module' | ||
} | ||
) | ||
walker.simple( | ||
parsed, | ||
{ | ||
Property (node) { | ||
const data = block.content.substring(node.start, node.end) | ||
try { | ||
if (key) { | ||
if (node.key.name === key) extractedData = eval(`({${data}})`)[key] // eslint-disable-line no-eval | ||
} else Object.assign(extractedData, eval(`({${data}})`)) // eslint-disable-line no-eval | ||
} catch (e) {} | ||
} | ||
}, | ||
walker.base | ||
) | ||
|
||
return extractedData | ||
} | ||
|
||
module.exports = extractComponentOptions | ||
// .bind( | ||
// this, | ||
// COMPONENT_OPTIONS_BLOCK, | ||
// COMPONENT_OPTIONS_KEY | ||
// ) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,8 @@ const AsyncCache = require('async-cache') | |
const consola = require('consola') | ||
const { promisify } = require('util') | ||
const { hostname } = require('os') | ||
|
||
const extractComponentOptions = require('./extractComponentOptions') | ||
const { COMPONENT_OPTIONS_BLOCK, COMPONENT_OPTIONS_KEY } = require('./constants') | ||
const defaultPublicPath = '/_nuxt/' | ||
|
||
module.exports = function module (moduleOptions) { | ||
|
@@ -54,13 +55,16 @@ module.exports = function module (moduleOptions) { | |
this.extendRoutes(routes => { | ||
// Get all static routes and ignore dynamic routes | ||
let staticRoutes = flattenRoutes(routes) | ||
.filter(r => !r.includes(':') && !r.includes('*')) | ||
.filter(r => !r.url.includes(':') && !r.url.includes('*')) | ||
.filter(route => { | ||
return extractComponentOptions(route.component, COMPONENT_OPTIONS_BLOCK, COMPONENT_OPTIONS_KEY) !== false | ||
}) | ||
|
||
// Exclude routes | ||
options.exclude.forEach(pattern => { | ||
const minimatch = new Minimatch(pattern) | ||
minimatch.negate = true | ||
staticRoutes = staticRoutes.filter(route => minimatch.match(route)) | ||
staticRoutes = staticRoutes.filter(route => minimatch.match(route.url)) | ||
}) | ||
|
||
// Create a cache for routes | ||
|
@@ -232,7 +236,7 @@ function flattenRoutes (router, path = '', routes = []) { | |
flattenRoutes(r.children, path + r.path + '/', routes) | ||
} | ||
if (r.path !== '') { | ||
routes.push(path + r.path) | ||
routes.push({ ...r, url: path + r.path }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This update can create a breaking change in the usage of the if yes, your commit message must respect the conventional commit to bump the release version as "major" update by the release script |
||
} | ||
}) | ||
return routes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<template> | ||
<div> | ||
/excluded-via-component-options | ||
</div> | ||
</template> | ||
<script> | ||
export default { | ||
sitemap:false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why limit the Maybe you can support the following options in addition of <script>
export default {
sitemap: {
changefreq: 'daily',
priority: 1,
lastmod: new Date(),
// ...
} |
||
} | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any
<page>.vue
file, it will always be ascript
element.Why create a constant?