|
|
@ -3,11 +3,9 @@ const slugify = require('slugify')
|
|
|
|
const merge = require('lodash.merge')
|
|
|
|
const merge = require('lodash.merge')
|
|
|
|
const nunjucks = require('nunjucks')
|
|
|
|
const nunjucks = require('nunjucks')
|
|
|
|
const assign = require('assign-deep')
|
|
|
|
const assign = require('assign-deep')
|
|
|
|
const fs = require('fs')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Media = require('./../factories/media.js')
|
|
|
|
const Media = require('./../factories/media.js')
|
|
|
|
const parseMarkdownFile = require('./../parsers/markdown.js')
|
|
|
|
const parseMarkdownFile = require('./../parsers/markdown.js')
|
|
|
|
const configStore = require('./../config.js')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Page - building from markdown file
|
|
|
|
* Page - building from markdown file
|
|
|
@ -35,8 +33,19 @@ class Page {
|
|
|
|
// getting dirPath for files for page
|
|
|
|
// getting dirPath for files for page
|
|
|
|
this._dirPath = this._resolvePath(parent)
|
|
|
|
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
|
|
|
|
// parse file
|
|
|
|
const result = parseMarkdownFile(fileString, this._dirPath)
|
|
|
|
const result = parseMarkdownFile(fileString, [
|
|
|
|
|
|
|
|
this._permalink, this._dirPath
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
// fields merge by default values
|
|
|
|
// fields merge by default values
|
|
|
|
this._fields = merge({
|
|
|
|
this._fields = merge({
|
|
|
@ -48,29 +57,17 @@ class Page {
|
|
|
|
hidden: false
|
|
|
|
hidden: false
|
|
|
|
}, result.fields)
|
|
|
|
}, 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
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
this._content = result.content
|
|
|
|
this._blocks = blocks
|
|
|
|
this._blocks = blocks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this._filename += '.' + this._fields.extensions
|
|
|
|
|
|
|
|
|
|
|
|
// check for fields and resolve media
|
|
|
|
// check for fields and resolve media
|
|
|
|
if (this._fields) {
|
|
|
|
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
|
|
|
|
// check for fields and resolve media
|
|
|
@ -78,10 +75,16 @@ class Page {
|
|
|
|
for (const key of Object.keys(this._blocks)) {
|
|
|
|
for (const key of Object.keys(this._blocks)) {
|
|
|
|
if (Array.isArray(this._blocks[key])) {
|
|
|
|
if (Array.isArray(this._blocks[key])) {
|
|
|
|
this._blocks[key].forEach((fields, index) => {
|
|
|
|
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 {
|
|
|
|
} 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'
|
|
|
|
|
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -123,12 +126,7 @@ class Page {
|
|
|
|
return fields
|
|
|
|
return fields
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
_resolveMediaSrc(field, dirPath) {
|
|
|
|
_resolveMediaSrc(field, dirPath) {
|
|
|
|
|
|
|
|
|
|
|
|
const media = new Media(dirPath)
|
|
|
|
const media = new Media(dirPath)
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof field === 'string' || field instanceof String) {
|
|
|
|
if (typeof field === 'string' || field instanceof String) {
|
|
|
|