Compare commits

...

7 Commits

@ -0,0 +1,4 @@
{
"/spritemap.js": "/spritemap.js?id=2dda73ecee3bb668b395026efda6524c",
"/public/css/styles.css": "/public/css/styles.css?id=c80a1181f87f3c3ef715844b545559f4"
}

@ -5,7 +5,7 @@
"packages/*"
],
"scripts": {
"build": "yarn workspace server run build",
"build": "yarn workspace frontend run build",
"start": "yarn workspace server run start"
}
}

@ -1,6 +1,9 @@
{
"name": "frontend",
"version": "0.1.0",
"scripts": {
"build": "npx mix"
},
"dependencies": {
"@tiny-components/plain-ui": "^0.6.0",
"riot": "^6.1.2"

@ -0,0 +1,3 @@
@import
'@tiny-components/plain-ui/src/scss/plain-ui';

@ -0,0 +1,24 @@
{{# layout('layout') }}
{{# section('content') { }}
<h1 class="site-header__title">
{{ page.data.title }}
</h1>
<div class="container">
<div class="grid">
<div class="col-12">
<div class="content">
{% if settings.404_message %}
{{ settings.404_message }}
{% endif %}
</div>
</div>
</div>
</div>
{{# endsection }}
{{# push('footer') { }}
{{# } }}

@ -1,19 +0,0 @@
{% layout 'layout.liquid' %}
{% block siteHeader %}
<h1 class="site-header__title">
{ site.404_title }
</h1>
{% endblock %}
{% block siteMain %}
<div class="container">
<div class="grid">
<div class="col-12">
<div class="content">
{ marked.parse(site.404_message) }
</div>
</div>
</div>
</div>
{% endblock %}

@ -0,0 +1,43 @@
<!doctype html>
<html lang="{{ it.settings.data.default_language }}">
<head>
<meta charset="utf-8">
<title>
{{ it.page.data.title }} | {{ it.settings.data.project_name }}
</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="{{ asset('/public/css/styles.css') }}" rel="stylesheet" type="text/css">
</head>
<body class="site-body {{ it.templateClass(it.page) }}">
<header class="site-header">
<div class="bar">
<div class="bar__start">
{{# if (isHome(it.page)) { }}
<h1 class="site-header__title">
{{ it.page.data.title }}
</h1>
{{# } else { }}
<a class="site-header__title">
{{ it.page.data.title }}
</a>
{{# } }}
</div>
</div>
</header>
<main class="site-main">
{{! it.body }}
</main>
<footer class="site-footer">
<div class="site-footer__copyright">
</div>
</footer>
</body>
</html>

@ -1,46 +0,0 @@
<!doctype html>
<html lang="en_EN">
<head>
<meta charset="utf-8">
<title>
{{ page.data.title }}
</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/css/styles.css" rel="stylesheet" type="text/css">
{% block head %}{% endblock %}
</head>
<body class="site-body page-{ siteClass(page) (page.data.slug) ? slug : 'home' }">
<header class="site-header">
{% block siteHeader %}
<h1 class="site-header__title">
{{ page.data.title }}
{{ options.data.title }}
</h1>
{% endblock %}
</header>
<main class="site-main">
{% block siteMain %}
{% endblock %}
</main>
<footer class="site-footer">
{% block siteFooter %}
<div class="">
</div>
{% endblock %}
<div class="site-footer__copyright">
</div>
</footer>
{% block script %}{% endblock %}
</body>
</html>

@ -0,0 +1,14 @@
{{# layout('layout') }}
{{# const store = await it.injectStore('post') }}
{{# const posts = await store.find() }}
{{# if (posts.data && posts.data.length > 0) { }}
{{# posts.data.forEach((post) => { }}
{{ post.title }}
<img src="{{ it.mediaUrl(post.teaser_media.id, { 'width': 500 }) }}" />
{{! it.marked.parse(post.teaser_content) }}
{{# }) }}
{{# } else { }}
{{# } }}

@ -1,13 +1,11 @@
{% layout 'layout.liquid' %}
{{# layout('layout') }}
{% block siteMain %}
<div class="container">
<div class="grid">
<div class="col-12">
<div class="content">
{{ page.data.content }}
{{! it.marked.parse(it.page.data.content) }}
</div>
</div>
</div>
</div>
{% endblock %}

@ -1,13 +1,11 @@
{% layout 'layout.liquid' %}
{{# layout('layout') }}
{% block siteMain %}
<div class="container">
<div class="grid">
<div class="col-12">
<div class="content">
{ marked.parse(page.data.content) }
{{! it.parseMarkdown(it.page.data.content) }}
</div>
</div>
</div>
</div>
{% endblock %}

@ -0,0 +1,84 @@
const mix = require('laravel-mix')
const path = require('path')
require('laravel-mix-purgecss')
// plugins
const SvgSpritemapPlugin = require('svg-spritemap-webpack-plugin')
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel applications. By default, we are compiling the CSS
| file for the application as well as bundling up all the JS files.
|
*/
mix.webpackConfig({
module: {
rules: [{
test: /\.riot$/,
use: [{
loader: '@riotjs/webpack-loader',
options: {
hot: false
}
}]
}
]},
plugins: [
new SvgSpritemapPlugin([
'./node_modules/@tiny-components/plain-ui/src/icons/mono-icons/svg/*.svg',
'./icons/*.svg'
], {
output: {
filename: 'public/symbol-defs.svg',
chunk: {
keep: true
},
svgo: {
plugins: [{
name: 'convertStyleToAttrs',
active: true
},{
name: 'removeStyleElement',
active: true
}, {
name: 'removeAttrs',
params: {
attrs: 'fill'
}
}]
}
},
sprite: {
prefix: 'icon-'
}
})
]
})
mix
.setPublicPath('../../public')
//.js('js/app.js', 'public/js')
.sass('scss/styles.scss', 'css')
.purgeCss({
extend: {
content: [
path.join(__dirname, 'js/**/*.riot'),
path.join(__dirname, 'views/*.liquid')
]
}
})
.options({
terser: {
extractComments: false,
},
processCssUrls: false
})
.copyDirectory('node_modules/@tiny-components/plain-ui/src/fonts/**', '../../public/css')
.version()

@ -15,37 +15,56 @@ const server = fastify()
*
*/
import { Liquid } from 'liquidjs'
import * as Eta from 'eta'
import view from '@fastify/view'
const engine = new Liquid({
root: path.join(path.resolve(), '/../frontend/views'),
extname: '.liquid',
})
import { asset, templateClass, isHome, injectStore, mediaUrl } from './helpers/eta.js'
import { marked } from 'marked'
server.register(view, {
engine: {
liquid: engine
eta: Eta
},
root: path.join(path.resolve(), '/../frontend/views'),
extname: '.eta',
// adding function to templates
defaultContext: {
asset: asset,
templateClass: templateClass,
isHome: isHome,
injectStore: injectStore,
marked: marked,
mediaUrl: mediaUrl
},
options: {
tags: [ '{{', '}}' ],
includeViewExtension: true,
parse: {
exec: "#",
interpolate: "",
raw: "!"
},
useWith: true,
async: true
}
})
/**
* adding preHandler
*
*
*/
import SettingsStore from './stores/Settings.js'
import SettingsStore from './stores/settings.js'
// getting options from directus add to all views
server.addHook('preHandler', async function (request, response) {
const settingsStore = new SettingsStore()
const settings = await settingsStore.find()
response.locals = {
settings: settings
}
response.locals.settings = settings
})
// check url for paged
@ -53,30 +72,27 @@ server.addHook('onRequest', async function (request, response) {
const url = request.url
let pathname = url.split('/')
pathname.shift()
let pathname = url.split('/').shift()
// default value for paged
let paged = 1
// check if pathname has values
if (pathname.length > 0) {
// check if pathname has values and is not 404
if (pathname.length > 0 && request.url !== '/404') {
// try to get number
const result = Number(pathname[pathname.length - 1])
// is result is integer
// is result is an integer
if (Number.isInteger(result)) {
paged = result
// remove last element
// remove last from pathname, add default url to request,
// and check if pathname has more than one, join pathname for new url
pathname.pop()
request.raw.url = '/'
// @TODO change, thats looks strange
if (pathname.length > 0) {
request.raw.url = pathname.join('/')
} else {
request.raw.url = '/'
}
}
}
@ -102,7 +118,7 @@ import postHttp from './http/post.js'
// page and static has always the last routes, if no route before match, it try get a page
import sitemapHttp from './http/sitemap.js'
import pageHttp from './http/page.js'
import staticHttp from './http/static.js'
import publicHttp from './http/public.js'
server
.register(commentHttp, {
@ -114,6 +130,6 @@ server
})
.register(sitemapHttp)
.register(pageHttp)
.register(staticHttp)
.register(publicHttp)
export default server

@ -0,0 +1,85 @@
/**
* function similar to blade asset
*
* @param $path
* @return string
*
*/
function asset($path, $prefix = '/public')
{
// get flight
$app = Flight::app();
// getting basePath
$basePath = $app->get('basePath');
// path to mix-manifest
$file = $app->get('basePath').'mix-manifest.json';
if (file_exists($file)) {
$manifest = file_get_contents($file);
$files = json_decode($manifest, true);
if (isset($files[$prefix.$path])) {
$path = str_replace($prefix, '', $files[$prefix.$path]);
}
}
return $path;
}
/**
* getting name of view as slug
*
* @param array $page
* @return string
*
*/
function canonical()
{
if (isset($_SERVER['HTTPS'])) {
$canoncial = 'https';
} else {
$canoncial = 'http';
}
$canoncial .= '://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
return $canoncial;
}
/**
* getting title for head
*
* @param array $page
* @param array $site
* @return string
*/
function title($page, $site)
{
$title = [];
if (isset($site['data']['title'])) {
$title[] = $site['data']['title'];
}
// if not homepage set page title first
if ($page['data']['slug']) {
array_unshift($title, $page['data']['title']);
} else {
$title[] = $page['data']['title'];
}
return join(' | ', $title);
}
function styles($values) {
$result = '';
if ($values && is_array($values)) {
$result = implode(' ', $values);
}
return $result;
}

@ -12,8 +12,8 @@
const directusResponseHandler = {
single(entity, response) {
// if data is empty redirect to 404
if (entity.data.length === 0) {
// if data not exists or data is empty redirect to 404
if (!entity.data || entity.data.length === 0) {
return response.redirect('/404')
}
@ -25,7 +25,7 @@ const directusResponseHandler = {
entity.data.template = 'default'
}
return entity
response.locals.page = entity
}
}

@ -0,0 +1,138 @@
import slugify from 'slugify'
import { marked } from 'marked'
import * as fs from 'fs'
import path from 'path'
const basePath = path.join(path.resolve(), '/../../')
/**
* etaHelpers
*
* collection for helpers to extend eta
*
*
*/
/**
* asset - checks manifest.json for given path and return
* file path with id for cache busting
*
*
* @param {String} publicPath
*
*/
function asset(publicPath)
{
// getting basePath
let result = publicPath
// path to mix-manifest
const file = basePath + 'mix-manifest.json'
if (fs.existsSync(file)) {
const manifest = fs.readFileSync(file)
const files = JSON.parse(manifest)
if (files[publicPath]) {
result = files[publicPath]
}
}
return result
}
/**
* templateClass - parse template name to css-classname,
* use prefix, default is "page"
*
*
* @param {Object} entity
* @param {String} [prefix='page']
* @return {String}
*
*/
function templateClass(entity, prefix = 'page') {
if (entity.data && entity.data.template) {
prefix += '-' + entity.data.template
}
return prefix
}
/**
* isHome - check if entity is home,
* checks for permalink
*
*
* @param {Object} entity
* @return {Boolean}
*
*/
function isHome(entity) {
let result = false
if (entity.data && entity.data.permalink && entity.data.permalink === "/") {
result = true
}
return result
}
/**
* injectStore - import store, check if store exists and
* create object from class
*
*
* @param {String} name
* @return {Object}
*
*/
async function injectStore(name) {
const importPath = './../stores/' + name + '.js'
const filePath = basePath + 'packages/server/stores/' + name + '.js'
// if class not exists, throw exception
if (!fs.existsSync(filePath)) {
throw new Error(name + ' not exists!')
}
const StoreClass = await import(importPath)
const store = new StoreClass.default()
return store
}
/**
* mediaUrl - create url for assets from directus,
* default options are with access_token for permissions
*
*
* @param {String} id
* @param {Object} options
* @return {String}
*
*/
function mediaUrl(id, options = {})
{
let query
// merge options, default is access_token
options = Object.assign({
'access_token': process.env.DIRECTUS_API_TOKEN
}, options)
// create query
query = '?' + new URLSearchParams(options).toString();
return process.env.DIRECTUS_API_URL + '/assets/' + id + query;
}
export { asset, templateClass, isHome, injectStore, mediaUrl }

@ -17,9 +17,19 @@ export default async function(fastify, opts) {
*
*/
fastify.get('/404', async function(request, response) {
// create object for handling in template
const page = {
data: {
title: '404'
}
}
return response
.code(404)
.view('../frontend/views/404')
.view('../views/404', {
page: page
})
})
}

@ -1,11 +1,11 @@
import path from 'path'
import PageStore from './../stores/Page.js'
import PageStore from './../stores/page.js'
import directusResponseHandler from './../handlers/directusResponse.js'
/**
* page
* Page
*
* @author Björn Hase <me@herr-hase.wtf>
* @license http://opensource.org/licenses/MIT The MIT License
@ -29,7 +29,8 @@ export default async function(fastify, opts) {
// getting single page
const page = await pageStore.findOneByPermalink(request.url)
response.page = directusResponseHandler.single(page, response)
directusResponseHandler.single(page, response)
})
/**
@ -40,8 +41,7 @@ export default async function(fastify, opts) {
*
*/
fastify.get('/*', async function(request, response) {
return response.view('../frontend/views/templates/page/' + response.page.data.template, {
'page' : response.page
})
return response.view('../views/templates/page/' + response.locals.page.data.template)
})
}

@ -1,4 +1,6 @@
import PageStore from './../stores/Post.js'
import PostStore from './../stores/post.js'
import directusResponseHandler from './../handlers/directusResponse.js'
import path from 'path'
/**
@ -25,8 +27,8 @@ export default async function(fastify, opts) {
const postStore = new PostStore()
// getting single page
let post = await store.findOneBySlug(request.params.slug)
directusResponseHandler.one(post, response)
let post = await postStore.findOneBySlug(request.params.slug)
directusResponseHandler.single(post, response)
})
@ -38,8 +40,6 @@ export default async function(fastify, opts) {
*
*/
fastify.get('/:slug([-a-zA-Z0-9]{0,255})', async function(request, response) {
response.view('../frontend/views/templates/post/' + response.post.data.template, {
'page' : post
})
response.view('../views/templates/post/' + response.locals.page.data.template)
})
}

@ -18,7 +18,7 @@ export default async function(fastify, opts) {
*/
fastify.register(fastifyStatic, {
root: path.join(path.resolve(), '/../../public'),
prefix: '/static',
prefix: '/public',
preCompressed: true
})

@ -1,6 +1,6 @@
import path from 'path'
import PageStore from './../stores/Page.js'
import PageStore from './../stores/page.js'
import directusResponseHandler from './../handlers/directusResponse.js'

@ -1,7 +1,8 @@
{
"name": "server",
"requires": true,
"version": "0.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@directus/sdk": {
"version": "9.14.2",
@ -223,6 +224,11 @@
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow=="
},
"eta": {
"version": "1.12.3",
"resolved": "https://registry.npmjs.org/eta/-/eta-1.12.3.tgz",
"integrity": "sha512-qHixwbDLtekO/d51Yr4glcaUJCIjGVJyTzuqV4GPlgZo1YpgOKG+avQynErZIYrfM6JIJdtiG2Kox8tbb+DoGg=="
},
"etag": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
@ -386,11 +392,6 @@
"set-cookie-parser": "^2.4.1"
}
},
"liquidjs": {
"version": "9.39.1",
"resolved": "https://registry.npmjs.org/liquidjs/-/liquidjs-9.39.1.tgz",
"integrity": "sha512-TFu19Cml0K2T34UY50ZKUApHgiiEaayqNW9J3o3ubLQCuhMFhY7jqwNpY1oVvvAJxCCxVqL6bJnGc1Fktth0Fw=="
},
"lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
@ -618,6 +619,11 @@
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="
},
"slugify": {
"version": "1.6.5",
"resolved": "https://registry.npmjs.org/slugify/-/slugify-1.6.5.tgz",
"integrity": "sha512-8mo9bslnBO3tr5PEVFzMPIWwWnipGS0xVbYf65zxDqfNwmzYn1LpiKNrR6DlClusuvo+hDHd1zKpmfAe83NQSQ=="
},
"sonic-boom": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-3.0.0.tgz",

@ -12,8 +12,9 @@
"dayjs": "^1.11.4",
"dompurify": "^2.3.10",
"dotenv": "^10.0.0",
"eta": "^1.12.3",
"fastify": "^4.2.1",
"liquidjs": "^9.39.1",
"marked": "^4.0.18"
"marked": "^4.0.18",
"slugify": "^1.6.5"
}
}

@ -1,8 +1,11 @@
import DirectusAbstractStore from './DirectusAbstract.js'
import DirectusAbstractStore from './directusAbstract.js'
/**
* Comments
*
* @author Björn Hase <me@herr-hase.wtf>
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.node001.net/HerrHase/super-fastify-directus.git
*
*/
@ -11,7 +14,7 @@ class CommentStore extends DirectusAbstractStore {
/**
*
*
* @param {string} endpoint
* @param {String} endpoint
*
*/
constructor() {
@ -21,8 +24,9 @@ class CommentStore extends DirectusAbstractStore {
/**
* getting page by permalink
*
* @param {string} permalink
* @return {object}
* @param {String} permalink
* @return {Object}
*
*/
find(page, uuid, limit = 20) {
return this.items.readByQuery({
@ -43,6 +47,32 @@ class CommentStore extends DirectusAbstractStore {
})
}
/**
* getting page by permalink
*
* @param {String} permalink
* @return {Object}
*
*/
page(page, uuid, limit = 20) {
return this.items.readByQuery({
fields: [
'name',
'content',
'approved',
'belongs_to.comments_id'
],
filter: {
approved : true,
belongs_to : {
comments_id: uuid
}
},
limit : limit,
offset : ((page - 1) * limit)
})
}
}
export default CommentStore

@ -3,6 +3,9 @@ import { Directus } from '@directus/sdk';
/**
* Abstract Class for handling Directus Api
*
* @author Björn Hase <me@herr-hase.wtf>
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.node001.net/HerrHase/super-fastify-directus.git
*
*/

@ -1,8 +1,11 @@
import DirectusAbstractStore from './DirectusAbstract.js'
import DirectusAbstractStore from './directusAbstract.js'
/**
* Pages from Directus
*
* @author Björn Hase <me@herr-hase.wtf>
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.node001.net/HerrHase/super-fastify-directus.git
*
*/
@ -32,6 +35,7 @@ class PageStore extends DirectusAbstractStore {
'title',
'status',
'permalink',
'template',
'meta',
'content'
],

@ -1,14 +1,18 @@
import DirectusAbstractStore from './DirectusAbstract.js'
import DirectusAbstractStore from './directusAbstract.js'
/**
* Posts from Directus
* Posts from posts
*
* @author Björn Hase <me@herr-hase.wtf>
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.node001.net/HerrHase/super-fastify-directus.git
*
*/
class PostStore extends DirectusAbstractStore {
/**
* set name of endpoint
*
*
* @param {string} endpoint
@ -26,10 +30,11 @@ class PostStore extends DirectusAbstractStore {
* @return {object}
*/
find(page = 1, limit = 20) {
return this.items.readOne({
return this.items.readByQuery({
fields: [
'title',
'slug',
'status',
'user_created.first_name',
'user_created.last_name',
@ -40,7 +45,6 @@ class PostStore extends DirectusAbstractStore {
'teaser_media.description',
],
filter: {
slug : slug,
status : 'published',
published_at : {
'_nnull': true
@ -59,7 +63,7 @@ class PostStore extends DirectusAbstractStore {
* @return {object}
*/
findOneBySlug(slug) {
return this.items.readOne({
return this.items.readByQuery({
fields: [
'title',
'slug',

@ -1,7 +1,7 @@
import DirectusAbstractStore from './DirectusAbstract.js'
import DirectusAbstractStore from './directusAbstract.js'
/**
* Settings
* Settings from directus_settings
*
* @author Björn Hase <me@herr-hase.wtf>
* @license http://opensource.org/licenses/MIT The MIT License
@ -11,7 +11,7 @@ import DirectusAbstractStore from './DirectusAbstract.js'
class SettingsStore extends DirectusAbstractStore {
/**
*
* set name of endpoint
*
* @param {string} endpoint
*
@ -21,7 +21,7 @@ class SettingsStore extends DirectusAbstractStore {
}
/**
* getting setting
* get settings from endpoint
*
*
* @return {object}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,13 @@
(self["webpackChunkfrontend"] = self["webpackChunkfrontend"] || []).push([["spritemap"],{
/***/ "?c20d":
/*!******************************!*\
!*** spritemap-dummy-module ***!
\******************************/
/***/ (() => {
/***/ })
}]);
Loading…
Cancel
Save