1
0
mirror of https://github.com/typemill/typemill.git synced 2025-08-01 11:50:28 +02:00

Version 1.3.5 Consolidation

This commit is contained in:
trendschau
2020-04-20 19:21:56 +02:00
parent 5a8968efde
commit 55704bd69f
34 changed files with 726 additions and 426 deletions

View File

@@ -6,10 +6,13 @@ use \URLify;
class ParsedownExtension extends \ParsedownExtra
{
function __construct()
function __construct($showAnchor = NULL)
{
parent::__construct();
# show anchor next to headline?
$this->showAnchor = $showAnchor;
# math support
$this->BlockTypes['\\'][] = 'Math';
$this->BlockTypes['$'][] = 'Math';
@@ -30,8 +33,10 @@ class ParsedownExtension extends \ParsedownExtra
$this->visualMode = true;
}
public function text($text)
public function text($text, $relurl = null)
{
$this->relurl = $relurl ? $relurl : '';
$Elements = $this->textElements($text);
return $Elements;
@@ -117,20 +122,37 @@ class ParsedownExtension extends \ParsedownExtra
{
return;
}
$text = trim($text, ' ');
$Block = array(
'element' => array(
'name' => 'h' . min(6, $level),
'text' => $text,
'handler' => 'line',
'attributes' => array(
'id' => "$headline"
)
)
);
$Block = array(
'element' => array(
'name' => 'h' . min(6, $level),
'text' => $text,
'handler' => 'line',
'attributes' => array(
'id' => "$headline"
)
)
);
if($this->showAnchor && $level > 1)
{
$Block['element']['elements'] = array(
array(
'name' => 'a',
'attributes' => array(
'href' => $this->relurl . "#" . $headline,
'class' => 'tm-heading-anchor',
),
'text' => '#',
),
array(
'text' => $text,
)
);
}
$this->headlines[] = array('level' => $level, 'name' => $Block['element']['name'], 'attribute' => $Block['element']['attributes']['id'], 'text' => $text);
return $Block;

View File

@@ -2,7 +2,7 @@
namespace Typemill\Extensions;
use Typemill\Models\WriteYaml;
use Typemill\Models\WriteMeta;
class TwigMetaExtension extends \Twig_Extension
{
@@ -15,9 +15,30 @@ class TwigMetaExtension extends \Twig_Extension
public function getMeta($settings, $item)
{
$write = new WriteYaml();
$writeMeta = new WriteMeta();
$meta = $write->getPageMeta($settings, $item);
$meta = $writeMeta->getPageMeta($settings, $item);
if(!$meta OR $meta['meta']['title'] == '' OR $meta['meta']['description'] == '')
{
# create path to the file
$filePath = $settings['rootPath'] . $settings['contentFolder'] . $item->path;
# check if url is a folder and add index.md
if($item->elementType == 'folder')
{
$filePath = $filePath . DIRECTORY_SEPARATOR . 'index.md';
}
if(file_exists($filePath))
{
# get content
$content = file_get_contents($filePath);
# completes title and description or generate default meta values
$meta = $writeMeta->completePageMeta($content, $settings, $item);
}
}
return $meta;
}