From 271f2f955669e0fa3a5635ccf015931342511b33 Mon Sep 17 00:00:00 2001 From: Mehdi Baaboura Date: Mon, 15 Nov 2021 23:06:33 +0100 Subject: [PATCH] 1.1.0 (#6) * Resolve #1: Multi-language support * #2: Added MarkdownWikiController * Added RebuildStorageCacheCommand * Updated README.md * Fixed meta files not supporting multiple languages * Updated README.md * Updated version number * Added custom attributes to MarkdownWikiPage * Updated README.md * Updated version number --- README.md | 1 + composer.json | 2 +- src/Model/MarkdownWikiPage.php | 7 ++++++- src/Service/MarkdownWikiImporter.php | 12 +++++++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ef26b37..669fa3a 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ The file structure within your wiki directory is held simple. * `meta.yaml` files need to contain the following keys: `title` The page's title `description` The page's description + Any other keys will be passed on as "custom attributes". If you need any other data for a page, save it here. **Example:** If you want to create a page with the path `/account/creation`, you would need a folder with the path `/account/creation`. In that folder, you would create a file named `meta.yaml` and a file named `content.md`. The first contains meta data about your page, the second contains your actual page content. diff --git a/composer.json b/composer.json index bc36b80..e62c586 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "gigadrive/markdown-wiki-bundle", - "version": "1.0.0", + "version": "1.1.0", "type": "symfony-bundle", "license": "MIT", "authors": [ diff --git a/src/Model/MarkdownWikiPage.php b/src/Model/MarkdownWikiPage.php index 5122842..9e7a17a 100644 --- a/src/Model/MarkdownWikiPage.php +++ b/src/Model/MarkdownWikiPage.php @@ -24,7 +24,8 @@ public function __construct( protected array $title, protected array $description, protected string $path, - protected array $content + protected array $content, + protected array $customAttributes ) { } @@ -43,4 +44,8 @@ public function getPath(): string { public function getContent(): array { return $this->content; } + + public function getCustomAttributes(): array { + return $this->customAttributes; + } } \ No newline at end of file diff --git a/src/Service/MarkdownWikiImporter.php b/src/Service/MarkdownWikiImporter.php index 8ff423b..072cf0e 100644 --- a/src/Service/MarkdownWikiImporter.php +++ b/src/Service/MarkdownWikiImporter.php @@ -95,6 +95,7 @@ protected function readFilesInDirectory(string $path): ?MarkdownWikiPage { $description = []; $pagePath = "/" . $this->stripPathPrefix($path); $content = []; + $customAttributes = []; foreach ($finder as $file) { if (str_ends_with($file->getFilename(), ".md")) { @@ -117,6 +118,15 @@ protected function readFilesInDirectory(string $path): ?MarkdownWikiPage { $title[$language] = $meta["title"]; $description[$language] = $meta["description"]; + $customAttributes[$language] = []; + + foreach ($meta as $key => $value) { + if ($key === "title" || $key === "description") { + continue; + } + + $customAttributes[$language][$key] = $value; + } } } @@ -125,7 +135,7 @@ protected function readFilesInDirectory(string $path): ?MarkdownWikiPage { return null; } - return new MarkdownWikiPage($title, $description, $pagePath, $content); + return new MarkdownWikiPage($title, $description, $pagePath, $content, $customAttributes); } protected function stripPathPrefix($path): string {