Compare commits
No commits in common. 'main' and 'v0.2.0' have entirely different histories.
Before Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 1.5 MiB |
@ -1,4 +0,0 @@
|
||||
title: "Test"
|
||||
language: "de"
|
||||
domain: "test.lan"
|
||||
https: true
|
@ -1,112 +0,0 @@
|
||||
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
|
@ -1,34 +0,0 @@
|
||||
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