Skip to content

Commit

Permalink
Merge pull request #59 from nikolalardev/feature/DEVDOCS-WEBSITE-19-F…
Browse files Browse the repository at this point in the history
…ix-meta-tags

DEVDOCS-WEBSITE-19 - Fix meta tags
  • Loading branch information
DavidLambauer authored Sep 26, 2024
2 parents e08faec + 27195a5 commit 57fc9f4
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 20 deletions.
15 changes: 12 additions & 3 deletions app/Documentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Markdown\GithubFlavoredMarkdownConverter;
use Carbon\CarbonInterval;
use Illuminate\Contracts\Cache\Repository as Cache;
use League\CommonMark\Extension\FrontMatter\Output\RenderedContentWithFrontMatter;

class Documentation
{
Expand Down Expand Up @@ -78,19 +79,27 @@ public function getEditUrl($version, $page)
*
* @param string $version
* @param string $page
* @return string|null
* @return array|null
*/
public function get($version, $page)
{

return $this->cache->remember('docs.'.$version.'.'.$page, 5, function () use ($version, $page) {
$path = base_path('resources/docs/'.$version.'/'.$page.'.md');

if ($this->files->exists($path)) {
$content = $this->files->get($path);

$content = (new GithubFlavoredMarkdownConverter())->convert($content);

return $this->replaceLinks($version, $content);
$frontendMatter = [];
if ($content instanceof RenderedContentWithFrontMatter) {
$frontendMatter = $content->getFrontMatter();
}

return [
'content' => $this->replaceLinks($version, $content),
'frontendMatter' => $frontendMatter,
];
}

return null;
Expand Down
17 changes: 15 additions & 2 deletions app/Http/Controllers/DocsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

class DocsController extends Controller
{
public const DEFAULT_META_TITLE = 'Mage-OS - Community driven eCommerce';
public const DEFAULT_META_DESCRIPTION = 'The Mage-OS Association is a non-profit association Formed by people within the Magento community to represent and further the interests of that community as a whole: Merchants, developers, agencies, and all of the many people supporting and supported by this ecosystem.';
const DEFAULT_META_KEYWORDS = 'Mage-OS, Magento 2';

/**
* The documentation repository.
*
Expand Down Expand Up @@ -80,7 +84,12 @@ public function show($version, $page = null)
}

$sectionPage = $page ?: 'installation-guide';
$content = $this->docs->get($version, $sectionPage);
$docPage = $this->docs->get($version, $sectionPage);
$content = $docPage['content'];
$pageCustomData = $docPage['frontendMatter'];
$metaDescription = $pageCustomData['description'] ?? self::DEFAULT_META_DESCRIPTION;
$metaKeywords = $pageCustomData['keywords'] ?? self::DEFAULT_META_KEYWORDS;
$communityNote = $pageCustomData['communityNote'] ?? true;

if (is_null($content)) {
$otherVersions = $this->docs->versionsContainingPage($page);
Expand Down Expand Up @@ -116,14 +125,18 @@ public function show($version, $page = null)
}

return view('docs', [
'title' => count($title) ? $title->text() : null,
'title' => count($title) ? $title->text() : self::DEFAULT_META_TITLE,
'index' => $this->docs->getIndex($version),
'content' => $content,
'currentVersion' => $version,
'versions' => Documentation::getDocVersions(),
'currentSection' => $section,
'canonical' => $canonical,
'edit_link' => $this->docs->getEditUrl($version, $sectionPage),
'metaTitle' => count($title) ? $title->text() : self::DEFAULT_META_TITLE,
'metaDescription' => $metaDescription,
'metaKeywords' => $metaKeywords,
'communityNote' => $communityNote,
]);
}

Expand Down
5 changes: 4 additions & 1 deletion app/Markdown/GithubFlavoredMarkdownConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use League\CommonMark\Environment\EnvironmentInterface;
use League\CommonMark\Extension\Attributes\AttributesExtension;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Extension\FrontMatter\FrontMatterExtension;
use League\CommonMark\Extension\FrontMatter\Output\RenderedContentWithFrontMatter;

/**
* Converts GitHub Flavored Markdown to HTML.
Expand Down Expand Up @@ -45,14 +47,15 @@ public function __construct(array $config = [])
'normalize' => 'relative',
'placeholder' => '[TOC]',
];

$environment = new Environment($config);
$environment->addExtension(new CommonMarkCoreExtension());
$environment->addExtension(new GithubFlavoredMarkdownExtension());
$environment->addExtension(new AttributesExtension());
$environment->addExtension(new TorchlightExtension());
$environment->addExtension(new HeadingPermalinkExtension());
$environment->addExtension(new TableOfContentsExtension());

$environment->addExtension(new FrontMatterExtension());

parent::__construct($environment);
}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
"php": "^8.1",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.0",
"laravel/tinker": "^2.8",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"spatie/laravel-sitemap": "^6.0",
"symfony/browser-kit": "^6.0",
"symfony/yaml": "^6.4",
"torchlight/torchlight-commonmark": "^0.5.2",
"torchlight/torchlight-laravel": "^0.5.7"
},
Expand Down
76 changes: 74 additions & 2 deletions composer.lock

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div id="main-content">
@if ($communityNote)
<div class="gradient-box py-8 px-5 gap-3 flex flex-col mb-10">
<p style="margin-bottom: 0!important;">
<span class="block font-bold">📝 Community Note</span>
Expand All @@ -7,5 +8,6 @@
discrepancies or areas that could be improved.
</p>
</div>
@endif
{{ $slot }}
</div>
2 changes: 1 addition & 1 deletion resources/views/docs.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class="opacity-75"/>
</blockquote>
@endif

<x-accessibility.main-content-wrapper>
<x-accessibility.main-content-wrapper :communityNote="$communityNote">
{!! $content !!}
</x-accessibility.main-content-wrapper>
</section>
Expand Down
19 changes: 10 additions & 9 deletions resources/views/partials/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@
@endif

<!-- Primary Meta Tags -->
<meta name="title" content="Mage-OS - Community driven eCommerce">
<meta name="description" content="The Mage-OS Association is a non-profit association Formed by people within the Magento community to represent and further the interests of that community as a whole: Merchants, developers, agencies, and all of the many people supporting and supported by this ecosystem.">
<meta name="title" content="{{ $metaTitle }}">
<meta name="description" content="{{ $metaDescription }}">
<meta name="keywords" content="{{ $metaKeywords }}">

<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://mage-os.org/">
<meta property="og:title" content="Mage-OS - Community driven eCommerce">
<meta property="og:description" content="The Mage-OS Association is a non-profit association Formed by people within the Magento community to represent and further the interests of that community as a whole: Merchants, developers, agencies, and all of the many people supporting and supported by this ecosystem.">
<meta property="og:url" content="{{ $canonical ? url($canonical) : 'https://mage-os.org/' }}">
<meta property="og:title" content="{{ $metaTitle }}">
<meta property="og:description" content="{{ $metaDescription }}">
<meta property="og:image" content="https://mage-os.org/wp-content/uploads/2023/05/page-icon.png">

<!-- Twitter -->
<!-- Twitter / X -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://mage-os.org/">
<meta property="twitter:title" content="Mage-OS - Community driven eCommerce">
<meta property="twitter:description" content="The Mage-OS Association is a non-profit association Formed by people within the Magento community to represent and further the interests of that community as a whole: Merchants, developers, agencies, and all of the many people supporting and supported by this ecosystem.">
<meta property="og:url" content="{{ $canonical ? url($canonical) : 'https://mage-os.org/' }}">
<meta property="og:title" content="{{ $metaTitle }}">
<meta property="twitter:description" content="{{ $metaDescription }}">
<meta property="twitter:image" content="https://mage-os.org/wp-content/uploads/2023/05/page-icon.png">

<!-- Favicon -->
Expand Down
7 changes: 6 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
'twitter_username' => 'damienwebdev',
'location' => 'Richmond, VA',
]
]
],
'title' => 'Team',
'metaTitle' => DocsController::DEFAULT_META_TITLE,
'metaDescription' => DocsController::DEFAULT_META_DESCRIPTION,
'metaKeywords' => DocsController::DEFAULT_META_KEYWORDS,
'canonical' => 'team'
]);
})->name('team');

0 comments on commit 57fc9f4

Please sign in to comment.