Compare commits

..

4 Commits
v0.4.0 ... main

@ -1,6 +1,6 @@
{
"name": "@site-o-mat/core",
"version": "0.4.0",
"version": "0.5.0",
"build": "webpack",
"author": "Björn Hase <me@herr-hase.wtf>",
"main": "index.js",

@ -21,8 +21,8 @@ const configStore = require('./../config.js')
class Media {
constructor(path = NULL) {
this._path = path
constructor(dirPath = NULL) {
this._path = dirPath
this._DIR_ASSETS = '/assets/'
}
@ -43,11 +43,7 @@ class Media {
const filename = slugify(path.basename(src, extension))
// check for images in path
if (this._path && fs.existsSync(configStore.get('source') + this._path + '/' + src)) {
sourcePath = configStore.get('source') + this._path + '/' + src
} else {
sourcePath = configStore.get('source') + '/' + src
}
sourcePath = this._getSourcePath(src)
// getting sharp
const process = sharp(sourcePath)
@ -92,6 +88,30 @@ class Media {
return this._reduce(results)
}
/**
* get source path
*
* @param {String} src
* @return {String}
*
*/
_getSourcePath(src) {
let sourcePath = configStore.get('source') + '/' + src
if (Array.isArray(this._path)) {
if (fs.existsSync(configStore.get('source') + this._path[0] + '/' + src)) {
sourcePath = configStore.get('source') + this._path[0] + '/' + src
} else if (fs.existsSync(configStore.get('source') + this._path[1] + '/' + src)) {
sourcePath = configStore.get('source') + this._path[1] + '/' + src
}
} else if (this._path && fs.existsSync(configStore.get('source') + this._path + '/' + src)) {
sourcePath = configStore.get('source') + this._path + '/' + src
}
return sourcePath
}
/**
* if only full is in results, reduce object to string
*

@ -3,9 +3,11 @@ const slugify = require('slugify')
const merge = require('lodash.merge')
const nunjucks = require('nunjucks')
const assign = require('assign-deep')
const fs = require('fs')
const Media = require('./../factories/media.js')
const parseMarkdownFile = require('./../parsers/markdown.js')
const configStore = require('./../config.js')
/**
* Page - building from markdown file
@ -55,6 +57,12 @@ class Page {
this._permalink = this._dirPath + '/' + this._slug
}
// check if page is in subdirectory
if (fs.existsSync(configStore.get('source') + this._permalink) && this._slug) {
this._dirPath += '/' + this._slug
this._filename = 'index'
}
this._filename += '.' + this._fields.extensions
this._content = result.content
@ -115,7 +123,12 @@ class Page {
return fields
}
/**
*
*
*/
_resolveMediaSrc(field, dirPath) {
const media = new Media(dirPath)
if (typeof field === 'string' || field instanceof String) {

@ -1,5 +1,6 @@
const { XMLParser, XMLBuilder, XMLValidator} = require('fast-xml-parser')
const dayjs = require('dayjs')
const assign = require('assign-deep')
/**
*
@ -19,7 +20,11 @@ class Sitemap {
*
*/
constructor(site) {
this._site = site
this._site = assign({
'sitemap': {
'use_permalinks': true
}
}, site)
this._urls = []
}
@ -31,8 +36,15 @@ class Sitemap {
*/
addPage(page) {
if (this._isValid(page)) {
let path = page.permalink
if (this._site.sitemap.use_permalinks === false) {
path = page.path
}
this._urls.push({
loc: 'https://' + this._site.domain + page.path,
loc: 'https://' + this._site.domain + path,
lastmod: dayjs().format()
})
}

@ -54,7 +54,7 @@ describe('Page /blog/index.md', function () {
})
it('path', function() {
assert.equal(page.path, '/blog.html')
assert.equal(page.path, '/blog/index.html')
})
it('permalink', function() {
@ -63,9 +63,9 @@ describe('Page /blog/index.md', function () {
it('fields has media src', function() {
assert.deepEqual(page.media.src, {
"300": "/assets/88c010ea/4ca9b5f5/6024c57d/05899fae/a33d9a45/dog300.webp",
"500x100": "/assets/88c010ea/4ca9b5f5/6024c57d/05899fae/a33d9a45/dog500x100.webp",
"full": "/assets/88c010ea/4ca9b5f5/6024c57d/05899fae/a33d9a45/dog.webp"
"300": "/assets/a6c45d17/11bf0a4e/a2b1d75d/dc85ca56/71c63294/dog300.webp",
"500x100": "/assets/a6c45d17/11bf0a4e/a2b1d75d/dc85ca56/71c63294/dog500x100.webp",
"full": "/assets/a6c45d17/11bf0a4e/a2b1d75d/dc85ca56/71c63294/dog.webp"
})
})
})

@ -25,10 +25,10 @@ describe('Sitemap', function () {
// check results
it('loc-tag with url', function() {
assert.match(sitemap.getXmlAsString(), /<loc>https:\/\/test.lan\/blog\/article.html<\/loc>/)
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\/index.html<\/loc>/)
assert.notMatch(sitemap.getXmlAsString(), /<loc>https:\/\/test.lan\/<\/loc>/)
})
})

Loading…
Cancel
Save