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 website custom metadata #81

Merged
merged 11 commits into from
Oct 18, 2020
14 changes: 14 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ You can find more details about your region on [AWS documentation](https://docs.

For other providers you can check [Scaleway Object Storage](https://www.scaleway.com/en/docs/object-storage-feature/) or [digitalOcean Spaces](https://www.digitalocean.com/docs/spaces/resources/s3-sdk-examples/)


### Custom metadata

If you want to customize headers metadata (for google analytics or others), you can specify metadata as following
```dotenv

CUSTOM_META="
<meta name='description' content='My Knowledge website'>
<link rel='stylesheet' href='/custom.css'/>
"

```
tooltip: This allows you to load custom css/js if needed

### ReadOnly/ReadWrite Mode

You can enable/disable readonly mode by setting the following property/
Expand Down
7 changes: 0 additions & 7 deletions assets/js/pages/article/read/ReadArticle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
import TableOfContent from "pages/article/read/TableOfContent";
import ArticleNotFound from "pages/article/read/ArticleNotFound";
import ArticleContent from "pages/article/read/ArticleContent";

import changePageTitleMixin from "mixins/changePageTitleMixin";

export default {
name: "ReadArticle",
components: {ArticleContent, ArticleNotFound, TableOfContent},
Expand Down Expand Up @@ -93,7 +91,6 @@
},
onBreakpointChanged(collapsed) {
this.$store.commit("setTocCollapsed", collapsed);

if (!collapsed && this.$store.getters.getTocCollapsed) {
this.$store.commit("setTocCollapsed", false)
}
Expand All @@ -110,16 +107,12 @@
</script>

<style scoped>

.toc {
display: flex;
justify-content: flex-end;
flex: 0 0 auto;
}

.toc-sider {
background: none;
}


</style>
9 changes: 5 additions & 4 deletions config/packages/twig.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
twig:
default_path: '%kernel.project_dir%/templates'
globals:
build_version: "%build_version%"
permissions: '@App\Services\Permissions'
default_path: '%kernel.project_dir%/templates'
globals:
build_version: "%build_version%"
metadata: "%custom_metadata%"
permissions: '@App\Services\Permissions'
3 changes: 3 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ parameters:
secret: "%env(S3_SECRET)%"
endpoint: "%env(S3_ENDPOINT)%"
use_path_style_endpoint: true
env(CUSTOM_META): |
<meta name="description" content="Knowledge is power">
custom_metadata: "%env(CUSTOM_META)%"

services:
# default configuration for services in *this* file
Expand Down
14 changes: 8 additions & 6 deletions src/Controller/KnowledgeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Annotations\RouteExposed;
use App\Services\FileLoader\EmptyFile;
use App\Services\FileLoader\ExtensionToMimeConverter;
use App\Services\FileLoader\File;
use App\Services\FileLoader\FileLoader;
use App\Services\FileLoader\MarkdownFile;
Expand All @@ -23,20 +24,22 @@
*/
class KnowledgeController extends AbstractController
{

/**
* @Route("/",defaults={"webpath"="/"}, methods={"GET"},name="_read_homepage")
* @Route("/{webpath}",requirements={"webpath"="[^_](?:(?!(?|_slides|_delete|/_edit|_routing_js)).)*"}, methods={"GET"},name="_read")
* @RouteExposed()
*/
public function index(\App\Services\FileLoader\File $file, Request $request)
public function index(\App\Services\FileLoader\File $file, ExtensionToMimeConverter $extensionToMimeConverter, Request $request)
{
if ($file->fileInfo->isDir()) {
return $this->redirectToRoute("knowledge_read_homepage", ["webpath" => $file->fileInfo->getRelativePathname() . "/" . InternalSettings::DEFAULT_INDEX_FILE . ".md"]);
}
if (!($file instanceof MarkdownFile) && !($file instanceof EmptyFile)) {

return new BinaryFileResponse($file->fileInfo->getPathname());
return new BinaryFileResponse(
$file->fileInfo->getPathname(),
200,
["Content-Type" => $extensionToMimeConverter($file->fileInfo->getExtension())]
);
}
if ($request->getPreferredFormat() === "html") {
// this behavior is for vue
Expand Down Expand Up @@ -131,8 +134,7 @@ public function delete(Permissions $permissions, MetadataManager $metadataManage
* @Route("/_upload", methods={"POST"},name="_upload_home")
* @RouteExposed()
*/
public
function upload(MetadataManager $metadataManager, Request $request, File $file, ParameterBagInterface $parameterBag)
public function upload(MetadataManager $metadataManager, Request $request, File $file, ParameterBagInterface $parameterBag)
{
$relativePathName = "/" . $file->fileInfo->getRelativePath() . "/";
$parentFullPath = $file->fileInfo->getPath() . "/";
Expand Down
2 changes: 1 addition & 1 deletion src/Services/FileLoader/ExtensionToMimeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace App\Services\FileLoader;



class ExtensionConverter
{
private $availableExtensions = [
Expand All @@ -15,6 +16,5 @@ class ExtensionConverter
function Apply($extension = "txt")
{
return $this->availableExtensions[$extension] ?? $this->availableExtensions["_default"];

}
}
3 changes: 2 additions & 1 deletion templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
<script src="https://kit.fontawesome.com/63a539fbd1.js" crossorigin="anonymous"></script>
{{ encore_entry_link_tags('app') }}
{% block stylesheets %}{% endblock %}
{{ metadata|raw }}
</head>
<body>

<div id="app"></div>
<div id="app"></div>

{% block javascripts %}{% endblock %}
<script type="application/javascript">
Expand Down
Loading