Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding meta title #80

Merged
merged 9 commits into from
Oct 18, 2020
5 changes: 4 additions & 1 deletion assets/js/pages/article/read/ReadArticle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
v-if="$store.getters.getCurrentArticle"
:key="$store.getters.getCurrentArticle.file.path"
v-hotkey="keymap">

<a-row type="flex">
<a-col class="article-content-col"
:style="{ width : $store.getters.getTocCollapsed ? '100%' : 'calc(100% - 250px)' }">
<div v-if="$store.getters.getCurrentArticle.file.metadata.title" class="hero">
<h1>{{ $store.getters.getCurrentArticle.file.metadata.title }}</h1>
</div>
<article-content/>
</a-col>
<a-layout-sider v-model="tocCollapsed"
Expand Down Expand Up @@ -119,4 +121,5 @@
background: none;
}


</style>
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"symfony/serializer-pack": "^1.0",
"symfony/twig-pack": "^1.0",
"symfony/webpack-encore-bundle": "^1.7",
"symfony/yaml": "5.1.*"
"symfony/yaml": "5.1.*",
"zoon/commonmark-ext-youtube-iframe": "^1.1"
},
"require-dev": {
"symfony/debug-pack": "1.*",
Expand Down
41 changes: 40 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/Services/FileLoader/ExtensionToMimeConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php


namespace App\Services\FileLoader;


class ExtensionConverter
{
private $availableExtensions = [
"css" => "text/css",
"txt" => "text/plain",
"_default" => "application/octet-stream",
];

function Apply($extension = "txt")
{
return $this->availableExtensions[$extension] ?? $this->availableExtensions["_default"];

}
}
26 changes: 19 additions & 7 deletions src/Services/FileLoader/MarkdownParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use League\CommonMark\Event\DocumentParsedEvent;
use League\CommonMark\Extension\Autolink\AutolinkExtension;
use League\CommonMark\Extension\ExternalLink\ExternalLinkExtension;
use League\CommonMark\Extension\ExternalLink\ExternalLinkProcessor;
use League\CommonMark\Extension\GithubFlavoredMarkdownExtension;
use League\CommonMark\Extension\Table\TableExtension;
use League\CommonMark\Extension\TaskList\TaskListExtension;
Expand All @@ -24,6 +23,7 @@
use Spatie\YamlFrontMatter\YamlFrontMatter;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Yaml\Exception\ParseException;

class MarkdownParser
{
Expand All @@ -39,8 +39,15 @@ class MarkdownParser

public function parse(MarkdownFile &$file)
{

$fileContent = YamlFrontMatter::parse($file->markdownContent);
$body = $file->markdownContent;
$metadata = [];
try {
$fileContent = YamlFrontMatter::parse($file->markdownContent);
$body = $fileContent->body();
$metadata = $fileContent->matter();
} catch (ParseException $exception) {
//do nothing
}

$environment = Environment::createCommonMarkEnvironment()
->addExtension(new GithubFlavoredMarkdownExtension())
Expand All @@ -57,13 +64,18 @@ public function parse(MarkdownFile &$file)
->addBlockRenderer(Heading::class, $headingWrapper = new HeadingWrapper())
->addEventListener(DocumentParsedEvent::class, new CustomExternalLinkProcessor(
$this->requestStack->getCurrentRequest()->getBaseUrl()
));
$converter = new CommonMarkConverter([], $environment);
));
$environment->addExtension(new \Zoon\CommonMark\Ext\YouTubeIframe\YouTubeIframeExtension());
$converter = new CommonMarkConverter([
'youtube_iframe_width' => 600,
'youtube_iframe_height' => 300,
'youtube_iframe_allowfullscreen' => true,
], $environment);


$file->content = $converter->convertToHtml($fileContent->body());
$file->content = $converter->convertToHtml($body);
$file->tree = $headingWrapper->extractTOC();
$file->metadata = $this->serializer->deserialize(json_encode($fileContent->matter()), Metadata::class, "json");
$file->metadata = $this->serializer->deserialize(json_encode($metadata), Metadata::class, "json");
return $file;
}
}
3 changes: 3 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,8 @@
},
"webmozart/assert": {
"version": "1.7.0"
},
"zoon/commonmark-ext-youtube-iframe": {
"version": "1.1.1"
}
}