main v0.4.0
HerrHase 1 year ago
parent 741c87114b
commit 6f0a443114

@ -13,7 +13,6 @@ finished, it was only a proof of concept. But now it works for created a entire
Next will be,
* Some more Tests
* Image Handling in Markdown
Maybe later,
@ -200,6 +199,30 @@ media:
---
```
Options from Sharp can be add on two different ways. As "options" for all Sizes or
you can simply add options to a sizes, that means the main options will be ignored.
```
---
title: "health goth DIY tattooed"
view: "home.njk"
meta:
description: "La"
media:
teaser:
src:
src: '_images/dog.jpg'
sizes:
- width: 300
- width: 500
height: 100
position: 'left'
alt: "cold-pressed"
options:
position: 'right'
---
```
## Queries
Queries can be used in Templates to get Pages.

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

@ -22,4 +22,6 @@ bicycle rights sartorial godard slow-carb thundercats art party cray JOMO. Truff
## Bitters kale chips chambray activated charcoal
wolf keffiyeh hell of selfies. Wolf readymade shoreditch flexitarian venmo single-origin coffee, knausgaard fit actually street art cold-pressed iPhone gatekeep. Migas bruh adaptogen semiotics marfa pickled yuccie. Locavore normcore lomo, shoreditch fashion axe actually glossier iPhone photo booth blue bottle DIY XOXO williamsburg. Pinterest whatever taxidermy, kale chips prism XOXO schlitz twee tote bag woke swag. Wayfarers fashion axe heirloom humblebrag synth. Whatever succulents PBR&B, pop-up enamel pin echo park tonx stumptown taiyaki.
wolf keffiyeh hell of selfies. Wolf readymade shoreditch flexitarian venmo single-origin coffee, knausgaard fit actually street art cold-pressed iPhone gatekeep. Migas bruh adaptogen semiotics marfa pickled yuccie. Locavore normcore lomo, shoreditch fashion axe actually glossier iPhone photo booth blue bottle DIY XOXO williamsburg. Pinterest whatever taxidermy, kale chips prism XOXO schlitz twee tote bag woke swag. Wayfarers fashion axe heirloom humblebrag synth. Whatever succulents PBR&B, pop-up enamel pin echo park tonx stumptown taiyaki.
![_images/dog.jpg](_images/dog.jpg)

@ -37,11 +37,6 @@ class ConfigStore {
* @return {String|Object}
*/
get(key) {
if (!this._data?.[key]) {
throw new Error(key + ' not found in ConfigStore!')
}
return this._data[key]
}
}
@ -49,4 +44,4 @@ class ConfigStore {
// create instance
const instance = new ConfigStore();
module.exports = instance
module.exports = instance

@ -25,7 +25,7 @@ class Block {
constructor(fileString, dirPath) {
// parse string of file
const parsedFile = parseMarkdownFile(fileString)
const parsedFile = parseMarkdownFile(fileString, dirPath)
this._dirPath = dirPath

@ -30,8 +30,11 @@ class Page {
*/
constructor(file, parent, fileString, blocks = {}) {
// getting dirPath for files for page
this._dirPath = this._resolvePath(parent)
// parse file
const result = parseMarkdownFile(fileString)
const result = parseMarkdownFile(fileString, this._dirPath)
// fields merge by default values
this._fields = merge({
@ -46,7 +49,6 @@ class Page {
// adding filename for html as pathname and relative path in structure
this._filename = this._resolveFilename(file)
this._slug = this._resolveSlug(this._filename)
this._dirPath = this._resolvePath(parent)
this._permalink = this._dirPath
if (this._slug) {
@ -121,7 +123,11 @@ class Page {
}
if (typeof field === 'object' || field instanceof Object) {
field = media.resolve(field.src, field.sizes)
if (field.options) {
field = media.resolve(field.src, field.sizes, field.options)
} else {
field = media.resolve(field.src, field.sizes)
}
}
return field

@ -1,7 +1,10 @@
const { marked } = require('marked')
const configStore = require('./../config.js')
const Media = require('./../factories/media.js')
/**
*
*
*
*/
@ -38,6 +41,13 @@ function cleanUrl(sanitize, base, 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)
@ -59,6 +69,42 @@ const renderer = {
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
}
}

@ -1,6 +1,7 @@
const yaml = require('js-yaml')
const { marked } = require('marked')
const configStore = require('./../config.js')
const renderer = require('./../marked/renderer.js')
/**
@ -12,7 +13,7 @@ const renderer = require('./../marked/renderer.js')
*
*/
function parseMarkdownFile(fileString) {
function parseMarkdownFile(fileString, dirPath = '') {
// regex get yaml section and markdown
// thanks to, https://github.com/getgrav/grav
@ -35,6 +36,15 @@ function parseMarkdownFile(fileString) {
// if markdown section exits parse it to html 6565
if (matches?.[3]) {
// reset configStore
configStore.set('markedDirPath', false)
// check for dirPath and set it to configStore for marked/renderer.js
if (dirPath || dirPath === '') {
configStore.set('markedDirPath', dirPath)
}
marked.use({ renderer })
result.content = marked.parse(matches[3])
}

@ -29,6 +29,10 @@ describe('Page /index.md', function () {
it('permalink', function() {
assert.equal(page.permalink, '')
})
it('parsed content contains image', () => {
assert.match(page.content, /<img src="\/assets\/88c010ea\/4ca9b5f5\/6024c57d\/05899fae\/a33d9a45\/dog.webp" alt="_images\/dog.jpg">/)
})
})
describe('Page /blog/index.md', function () {

Loading…
Cancel
Save