main v0.4.1
HerrHase 1 year ago
parent 6f0a443114
commit 49a21861e8

@ -1,6 +1,6 @@
{
"name": "@site-o-mat/core",
"version": "0.4.0",
"version": "0.4.1",
"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
*

@ -33,8 +33,19 @@ class Page {
// getting dirPath for files for page
this._dirPath = this._resolvePath(parent)
// adding filename for html as pathname and relative path in structure
this._filename = this._resolveFilename(file)
this._slug = this._resolveSlug(this._filename)
this._permalink = this._dirPath
if (this._slug) {
this._permalink = this._dirPath + '/' + this._slug
}
// parse file
const result = parseMarkdownFile(fileString, this._dirPath)
const result = parseMarkdownFile(fileString, [
this._permalink, this._dirPath
])
// fields merge by default values
this._fields = merge({
@ -46,23 +57,17 @@ class Page {
hidden: false
}, result.fields)
// adding filename for html as pathname and relative path in structure
this._filename = this._resolveFilename(file)
this._slug = this._resolveSlug(this._filename)
this._permalink = this._dirPath
if (this._slug) {
this._permalink = this._dirPath + '/' + this._slug
}
this._filename += '.' + this._fields.extensions
this._content = result.content
this._blocks = blocks
this._filename += '.' + this._fields.extensions
// check for fields and resolve media
if (this._fields) {
this._fields = this._resolveMedia(this._fields, this._dirPath)
this._fields = this._resolveMedia(this._fields, [
this._permalink,
this._dirPath
])
}
// check for fields and resolve media
@ -70,10 +75,16 @@ class Page {
for (const key of Object.keys(this._blocks)) {
if (Array.isArray(this._blocks[key])) {
this._blocks[key].forEach((fields, index) => {
this._blocks[key][index] = this._resolveMedia(fields, this._dirPath + '/_blocks')
this._blocks[key][index] = this._resolveMedia(fields, [
this._permalink + '/_blocks',
this._dirPath + '/_blocks'
])
})
} else {
this._blocks[key] = this._resolveMedia(this._blocks[key], this._dirPath + '/_blocks')
this._blocks[key] = this._resolveMedia(this._blocks[key], [
this._permalink + '/_blocks',
this._dirPath + '/_blocks'
])
}
}
}

@ -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"
})
})
})

Loading…
Cancel
Save