Compare commits
15 Commits
Author | SHA1 | Date |
---|---|---|
HerrHase | c39f361697 | 1 year ago |
HerrHase | e1f6c52a12 | 1 year ago |
HerrHase | 6dcb72d83a | 1 year ago |
HerrHase | 49a21861e8 | 2 years ago |
HerrHase | 6f0a443114 | 2 years ago |
HerrHase | 741c87114b | 2 years ago |
HerrHase | 4ae23d8f63 | 2 years ago |
HerrHase | b213bf74ed | 2 years ago |
HerrHase | bbab557d8e | 2 years ago |
HerrHase | f30b3d7834 | 2 years ago |
HerrHase | 1cb628a96d | 2 years ago |
HerrHase | 2098b932b3 | 2 years ago |
HerrHase | b2af26e68f | 2 years ago |
HerrHase | 5d6aa96b59 | 2 years ago |
HerrHase | 0efa8adaab | 2 years ago |
After Width: | Height: | Size: 41 KiB |
After Width: | Height: | Size: 2.3 MiB |
After Width: | Height: | Size: 1.5 MiB |
@ -0,0 +1,4 @@
|
||||
title: "Test"
|
||||
language: "de"
|
||||
domain: "test.lan"
|
||||
https: true
|
@ -0,0 +1,112 @@
|
||||
const { marked } = require('marked')
|
||||
|
||||
const configStore = require('./../config.js')
|
||||
const Media = require('./../factories/media.js')
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
// copy from @marked/src/helpers.js, no export possible
|
||||
function cleanUrl(sanitize, base, href) {
|
||||
if (sanitize) {
|
||||
|
||||
let prot
|
||||
|
||||
try {
|
||||
prot = decodeURIComponent(unescape(href))
|
||||
.replace(nonWordAndColonTest, '')
|
||||
.toLowerCase()
|
||||
} catch (e) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
if (base && !originIndependentUrl.test(href)) {
|
||||
href = resolveUrl(base, href)
|
||||
}
|
||||
|
||||
try {
|
||||
href = encodeURI(href).replace(/%25/g, '%')
|
||||
} catch (e) {
|
||||
return null
|
||||
}
|
||||
|
||||
return href
|
||||
}
|
||||
|
||||
const renderer = {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} href
|
||||
* @param {string} title
|
||||
* @param {string} text
|
||||
*/
|
||||
link(href, title, text) {
|
||||
|
||||
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href)
|
||||
|
||||
if (href === null) {
|
||||
return text
|
||||
}
|
||||
|
||||
let out = '<a href="' + href + '"'
|
||||
|
||||
if (title) {
|
||||
out += ' title="' + title + '"'
|
||||
}
|
||||
|
||||
// check if url is external and add target
|
||||
if (href.match(/^(http|https):\/\//)) {
|
||||
out += ' target="_blank" rel="noopener" '
|
||||
}
|
||||
|
||||
out += '>' + text + '</a>'
|
||||
|
||||
return out
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} href
|
||||
* @param {string} title
|
||||
* @param {string} text
|
||||
*/
|
||||
image(href, title, text) {
|
||||
|
||||
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href)
|
||||
|
||||
if (href === null) {
|
||||
return text
|
||||
}
|
||||
|
||||
// check if href for image is relative
|
||||
if (!href.match(/^(http|https):\/\//)) {
|
||||
const markedDirPath = configStore.get('markedDirPath')
|
||||
|
||||
// check if dirPath are exists from options
|
||||
if (markedDirPath || markedDirPath === '') {
|
||||
const media = new Media(markedDirPath)
|
||||
href = media.resolve(href)
|
||||
}
|
||||
}
|
||||
|
||||
let out = `<img src="${href}" alt="${text}"`
|
||||
|
||||
if (title) {
|
||||
out += ` title="${title}"`
|
||||
}
|
||||
|
||||
out += this.options.xhtml ? '/>' : '>'
|
||||
|
||||
return out
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = renderer
|
@ -0,0 +1,34 @@
|
||||
const { assert } = require('chai')
|
||||
const fs = require('fs')
|
||||
|
||||
const PagesQuery = require('./../src/queries/pages.js')
|
||||
const configStore = require('./../src/config.js')
|
||||
const parseYamlFile = require('./../src/parsers/yaml.js')
|
||||
const Sitemap = require('./../src/factories/sitemap.js')
|
||||
|
||||
describe('Sitemap', function () {
|
||||
|
||||
configStore.set('source', './ressources')
|
||||
configStore.set('destination', './dist')
|
||||
|
||||
const file = fs.readFileSync('./ressources/site.yml', 'utf8')
|
||||
const siteConfig = parseYamlFile(file)
|
||||
|
||||
const query = new PagesQuery('./ressources')
|
||||
const results = query.find()
|
||||
|
||||
const sitemap = new Sitemap(siteConfig)
|
||||
|
||||
results.forEach((page) => {
|
||||
sitemap.addPage(page)
|
||||
})
|
||||
|
||||
// check results
|
||||
it('loc-tag with url', function() {
|
||||
assert.match(sitemap.getXmlAsString(), /<loc>https:\/\/test.lan\/blog\/article<\/loc>/)
|
||||
})
|
||||
|
||||
it('loc-tag has robotos:noindex and has missing', function() {
|
||||
assert.notMatch(sitemap.getXmlAsString(), /<loc>https:\/\/test.lan\/<\/loc>/)
|
||||
})
|
||||
})
|
Loading…
Reference in new issue