Commit 233492f7 authored by Tobias Buckdahn's avatar Tobias Buckdahn

Merge branch 'feature/part-pages' into 'master'

Part pages

See merge request !4
parents 2dcce0a2 2e8214db
......@@ -6,4 +6,6 @@ data/form-files/**
data/tntsearch/**
pages/images/tax-part/**
!pages/images/tax-part/dummy.md
!pages/images/tax-part/.gitkeep
\ No newline at end of file
!pages/images/tax-part/.gitkeep
pages/23.part/**
!pages/23.part/dummy.md
\ No newline at end of file
......@@ -53,4 +53,5 @@ redirects:
'/../techs/with/(shape.*)': '/techs/shapes/$1'
'/../techs/with/(.*angle.*)': '/techs/rotations/$1'
'/../techs/with/(.*length.*)': '/techs/offsets/$1'
'/../techs/with/(pattern.*)': '/techs/patterns/$1'
\ No newline at end of file
'/../techs/with/(pattern.*)': '/techs/patterns/$1'
'/../techs/using/part:(.+)': '/part/$1'
\ No newline at end of file
......@@ -14,4 +14,5 @@ content:
---
Noppen anheben
Abstand verkleinern
Hoch Höher
\ No newline at end of file
Hoch Höher
Offset
\ No newline at end of file
......@@ -13,4 +13,5 @@ content:
type: 'tech'
---
Higher studs
Lower distance
\ No newline at end of file
Lower distance
Offset
\ No newline at end of file
......@@ -12,4 +12,5 @@ content:
published: true
type: 'tech'
---
Noppe / Studs verschieben
\ No newline at end of file
Noppe / Studs verschieben
Offset
\ No newline at end of file
......@@ -12,4 +12,5 @@ content:
published: true
type: 'tech'
---
Lower distance
\ No newline at end of file
Lower distance
Offset
\ No newline at end of file
---
title: Technik vorschlagen
icon: icon.png
image: image.png
image: icon.png
form:
name: propose_tech
......
---
title: Propose Tech
icon: icon.png
image: image.png
image: icon.png
form:
name: propose_tech
......
......@@ -3,7 +3,14 @@ title: Teile
image: image.jpg # Photo by Rick Mason on Unsplash (edited)
icon: icon.png
terms:
taxonomy: part
pool: 'techs/using'
item_wrapper_classes: 'col-4 col-sm-3 col-md-2'
item_show_footer: false
content:
items:
- '@page.children': '/part'
order:
by: title
limit: 24
pagination: true
---
\ No newline at end of file
......@@ -3,7 +3,14 @@ title: Parts
image: image.jpg # Photo by Rick Mason on Unsplash (edited)
icon: icon.png
terms:
taxonomy: part
pool: 'techs/using'
item_wrapper_classes: 'col-4 col-sm-3 col-md-2'
item_show_footer: false
content:
items:
- '@page.children': '/part'
order:
by: title
limit: 24
pagination: true
---
\ No newline at end of file
---
title: Todo
content:
items:
- '@taxonomy.tag': 'translate'
order:
by: title
limit: 24
pagination: true
---
\ No newline at end of file
---
title: Dummy
published: false
tntsearch:
index: false
sitemap:
ignore: true
---
\ No newline at end of file
......@@ -5,6 +5,7 @@ use Grav\Common\Grav;
use Grav\Common\Plugin;
use Grav\Common\Uri;
use Grav\Plugin\BrickCamp\Techs;
use Grav\Plugin\BrickCamp\Terms;
use Grav\Plugin\BrickCamp\TermsTwigExtension;
use RocketTheme\Toolbox\Event\Event;
......@@ -45,6 +46,7 @@ class BrickCampPlugin extends Plugin
'onFormInitialized' => ['onFormInitialized', 0],
// 'onFormProcessed' => ['onFormProcessed', 0],
'onPageProcessed' => ['onPageProcessed', 0],
'onPagesInitialized' => ['onPagesInitialized', 0],
'onCollectionProcessed' => ['onCollectionProcessed', 0],
]);
}
......@@ -81,6 +83,11 @@ class BrickCampPlugin extends Plugin
}
}
public function onPagesInitialized(Event $event)
{
Terms::initTermPages('part', '/part');
}
/**
* Edit collections based on URI
*
......
......@@ -2,6 +2,7 @@
namespace Grav\Plugin\BrickCamp;
use Grav\Common\Grav;
use Grav\Common\Page\Page;
abstract class Terms
{
......@@ -108,4 +109,56 @@ abstract class Terms
return ucwords($term);
}
}
public static function initTermPages($taxonomy, $parent) {
$pages = Grav::instance()['pages'];
$path = $pages->find($parent)->path();
$terms = self::get($taxonomy);
foreach ($terms as $term) {
// check whether term page already exists
$route = $parent . '/' . $term;
$page = $pages->find($route);
if ($page) {
continue;
}
// get title and increase search visibility for shorter titles
$title = self::getTitle($taxonomy, $term);
$weight = round( 10 / str_word_count( $title ));
$content = str_repeat( $title . "\n", $weight );
// create file for page
$page = new Page;
$page->filePath($path . DIRECTORY_SEPARATOR . $term . DIRECTORY_SEPARATOR . 'collection.en.md');
$page->header( array(
'title' => $title,
'image' => 'image.png',
'icon' => 'image.png',
'content' => array(
'items' => array(
'@taxonomy.' . $taxonomy => $term
),
'limit' => 12,
'pagination' => true
),
'taxonomy' => array(
'tag' => 'translate'
)
));
$page->content($content);
$pages->addPage($page, $route);
$page->save();
// add image
$img_source = self::getImage($taxonomy, $term)['filepath'];
$img_dest = $path . DIRECTORY_SEPARATOR . $term . DIRECTORY_SEPARATOR . 'image.png';
copy($img_source, $img_dest);
// add german translation template
$page->filePath($path . DIRECTORY_SEPARATOR . $term . DIRECTORY_SEPARATOR . 'collection.de.md');
$pages->addPage($page, $route);
$page->save();
}
}
}
\ No newline at end of file
{% extends 'partials/base.html.twig' %}
{% set item_wrapper_classes = page.header.item_wrapper_classes %}
{% set item_show_footer = page.header.item_show_footer is defined ? page.header.item_show_footer : true %}
{# Adapt introduction to current filter (if enabled) #}
{% if page.header.filter_title %}
{% set params = uri.params(null, true) %}
......
{% set item_show_image = item_show_image is defined ? item_show_image : page.header.image %}
{# set item_show_content = item_show_content is defined ? item_show_content : page.content #}
{% set item_show_footer = item_show_footer is defined ? item_show_footer : page.title %}
{% set item_show_footer_icon = page.header.icon and page.header.icon != page.header.image %}
<div class="{{ item_wrapper_classes ?: 'col-sm-6 col-md-4 col-xl-3' }}">
<div class="{{ item_classes ?: 'mb-4' }} card mx-auto shadow-sm text-center">
......@@ -28,13 +29,14 @@
{% if item_show_footer %}
<div class="card-footer {{ page.header.icon ? 'd-flex justify-content-between align-items-center py-1 pr-1' }}">
<div class="card-footer {{ item_show_footer_icon ? 'd-flex justify-content-between align-items-center py-1 pr-1' }}">
{% block item_footer %}
<a href="{{ page.redirect ?: page.header.link ?: page.url }}" class="text-dark" tabindex="-1">
<span class="caption text-truncate {{ page.header.icon ? '' : 'd-block' }}">{{ page.title }}</span>
<span class="caption text-truncate {{ item_show_footer_icon ? '' : 'd-block' }}">{{ page.title }}</span>
</a>
{% if page.header.icon %}
{% if item_show_footer_icon %}
<a href="{{ page.redirect ?: page.header.link ?: page.url }}" tabindex="-1">
<img class="img-fluid" src="{{ page.media[page.header.icon].resize(48,48).url }}" alt="{{ page.title }}">
</a>
......
......@@ -2,42 +2,48 @@
{% extends '/partials/item/base.html.twig' %}
{% block item_image %}
{% switch page.collection|length %}
{% case 1 %}
{% set width = [300] %}
{% set height = [300] %}
{% set class = [''] %}
{% case 2 %}
{% set width = [150, 150] %}
{% set height = [300, 300] %}
{% set class = ['border-right text-right', 'border-left text-left'] %}
{% case 3 %}
{% set width = [150, 150, 150] %}
{% set height = [300, 150, 150] %}
{% set class = ['border-right text-right', 'border-left border-bottom', 'border-left border-top'] %}
{% default %}
{% set width = [150, 150, 150, 150] %}
{% set height = [150, 150, 150, 150] %}
{% set class = ['border-right text-right border-bottom', 'border-left border-bottom',
'border-right text-right border-top', 'border-left border-top'] %}
{% endswitch %}
{% if item_image or page.header.image %}
{{ parent() }}
{% else %}
{% switch page.collection|length %}
{% case 1 %}
{% set width = [300] %}
{% set height = [300] %}
{% set class = [''] %}
{% case 2 %}
{% set width = [150, 150] %}
{% set height = [300, 300] %}
{% set class = ['border-right text-right', 'border-left text-left'] %}
{% case 3 %}
{% set width = [150, 150, 150] %}
{% set height = [300, 150, 150] %}
{% set class = ['border-right text-right', 'border-left border-bottom', 'border-left border-top'] %}
{% default %}
{% set width = [150, 150, 150, 150] %}
{% set height = [150, 150, 150, 150] %}
{% set class = ['border-right text-right border-bottom', 'border-left border-bottom',
'border-right text-right border-top', 'border-left border-top'] %}
{% endswitch %}
<a href="{{ page.redirect ?: page.header.link ?: page.url }}" class="{{ item_image_link_classes ?: 'card-image text-decoration-none' }}">
<div class="card-img-grid text-left">
{% set count = page.collection|length == 4 ? 4 : 3 %}
{% for example in page.collection[:count] %}
<img
class="img-fluid card-img-top w-auto {{ class[loop.index0] }}"
src="{{ example.media[example.header.image].cropZoom(width[loop.index0], height[loop.index0]).url }}"
alt="{{ example.title }}"
>
{% endfor %}
{% if page.collection|length > 4 %}
{# See issue https://github.com/getgrav/grav-plugin-pagination/issues/29 #}
{% set fullsize = page.header.unpaginated ? page.collection('unpaginated') : page.collection %}
<span class="more-count text-secondary text-center {{ class[3] }}">{{ fullsize|length - 3 }}</span>
{% endif %}
</div>
</a>
<a href="{{ page.redirect ?: page.header.link ?: page.url }}"
class="{{ item_image_link_classes ?: 'card-image text-decoration-none' }}"
title="{{ page.title }}">
<div class="card-img-grid text-left">
{% set count = page.collection|length == 4 ? 4 : 3 %}
{% for example in page.collection[:count] %}
<img
class="img-fluid card-img-top w-auto {{ class[loop.index0] }}"
src="{{ example.media[example.header.image].cropZoom(width[loop.index0], height[loop.index0]).url }}"
alt="{{ example.title }}"
>
{% endfor %}
{% if page.collection|length > 4 %}
{# See issue https://github.com/getgrav/grav-plugin-pagination/issues/29 #}
{% set fullsize = page.header.unpaginated ? page.collection('unpaginated') : page.collection %}
<span class="more-count text-secondary text-center {{ class[3] }}">{{ fullsize|length - 3 }}</span>
{% endif %}
</div>
</a>
{% endif %}
{% endblock %}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment