From e04ba5928592853018592502da55c95ab39a4192 Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Mon, 26 Sep 2022 13:22:00 +0200 Subject: [PATCH] feat(docsify+exts): ability to add docs for extensions --- docs/users/fr/_navbar.md | 1 + .../controllers/DocumentationController.php | 25 ++++-- javascripts/documentation.js | 88 +++++++++++-------- styles/documentation.css | 3 + templates/documentation.twig | 7 +- 5 files changed, 80 insertions(+), 44 deletions(-) diff --git a/docs/users/fr/_navbar.md b/docs/users/fr/_navbar.md index b93347a2e5..fb30fb7f69 100644 --- a/docs/users/fr/_navbar.md +++ b/docs/users/fr/_navbar.md @@ -8,6 +8,7 @@ * [Administration](/docs/users/fr/admin.md) * [Installation](/docs/users/fr/webmaster.md) * [Développement](/docs/users/fr/dev.md) +* [Extensions](/ ':id=extensions-links') * 🔧 * [Comment contribuer à cette doc](/docs/users/README.md) * [Liste des choses à faire sur la doc](/docs/users/TODO.md) diff --git a/includes/controllers/DocumentationController.php b/includes/controllers/DocumentationController.php index 96333b994f..008c053a8b 100644 --- a/includes/controllers/DocumentationController.php +++ b/includes/controllers/DocumentationController.php @@ -13,10 +13,23 @@ class DocumentationController extends YesWikiController */ public function show() { - return new Response($this->render('@core/documentation.twig', [ - 'config' => $this->wiki->config, - 'i18n' => json_encode($GLOBALS['translations_js']), - 'locale' => $GLOBALS['prefered_language'] - ])); + return new Response($this->render('@core/documentation.twig', [ + 'config' => $this->wiki->config, + 'i18n' => $GLOBALS['translations_js'], + 'locale' => $GLOBALS['prefered_language'], + 'extensions' => $this->getExtensionsWithDocs() + ])); } -} \ No newline at end of file + + private function getExtensionsWithDocs(): array + { + $extensions = []; + foreach ($this->wiki->extensions as $extName => $extPath) { + $localizedPath = "{$extPath}docs/{$GLOBALS['prefered_language']}/README.md"; + $path = "{$extPath}docs/README.md"; + $docPath = glob($localizedPath)[0] ?? glob($path)[0] ?? null; + if ($docPath) $extensions[] = ["name" => $extName, "docPath" => $docPath]; + } + return $extensions; + } +} diff --git a/javascripts/documentation.js b/javascripts/documentation.js index 13a15aa9d4..2c2c1b279b 100644 --- a/javascripts/documentation.js +++ b/javascripts/documentation.js @@ -41,14 +41,17 @@ window.$docsify = { html = html.replace(/ - ` + if (vm.route.file.match(/^docs\/.*$/)){ + const url = `https://github.com/YesWiki/yeswiki/edit/doryphore-dev/${vm.route.file}` + const footer = ` +
+ ` + html = html + footer; + } - return html + footer; + return html; }); hook.doneEach(function() { @@ -112,34 +115,49 @@ function initCustomNavMenu() { if (document.querySelector("nav .search-icon")) return // search icon - let searchIcon = document.createElement('div') - searchIcon.innerHTML = "" - searchIcon.classList = "search-icon" - searchIcon.addEventListener('click', function() { - document.querySelector('aside').classList.toggle('open') - document.querySelector('nav > ul').classList.remove('open') - document.querySelector('.menu-icon').classList.remove("open") - }) - document.querySelector('nav').appendChild(searchIcon) + let searchIcon = document.createElement('div') + searchIcon.innerHTML = "" + searchIcon.classList = "search-icon" + searchIcon.addEventListener('click', function() { + document.querySelector('aside').classList.toggle('open') + document.querySelector('nav > ul').classList.remove('open') + document.querySelector('.menu-icon').classList.remove("open") + }) + document.querySelector('nav').appendChild(searchIcon) - // menu icon - let menuIcon = document.createElement('div') - menuIcon.innerHTML = "" - menuIcon.classList = "menu-icon" - menuIcon.addEventListener('click', function() { - document.querySelector('nav > ul').classList.toggle('open') - this.classList.toggle("open") - }) - document.querySelector('nav').appendChild(menuIcon) + // menu icon + let menuIcon = document.createElement('div') + menuIcon.innerHTML = "" + menuIcon.classList = "menu-icon" + menuIcon.addEventListener('click', function() { + document.querySelector('nav > ul').classList.toggle('open') + this.classList.toggle("open") + }) + document.querySelector('nav').appendChild(menuIcon) - // Back button url correct - let backBtn = document.querySelector("#back") - if (backBtn) { - backBtn.href = baseUrl - const backBtnClone = backBtn.cloneNode(true) - const li = document.createElement('li') - li.appendChild(backBtnClone) - const nav = document.querySelector('nav > ul') - nav.insertBefore(li, nav.children[0]) - } + // Back button url correct + let backBtn = document.querySelector("#back") + if (backBtn) { + backBtn.href = baseUrl + const backBtnClone = backBtn.cloneNode(true) + const li = document.createElement('li') + li.appendChild(backBtnClone) + const nav = document.querySelector('nav > ul') + nav.insertBefore(li, nav.children[0]) + } + // extensions menu + const element = document.getElementById("extensions-links") + if (extensions.length > 0) { + element.removeAttribute("href") + let list = document.createElement('ul'); + let html = '' + extensions.forEach((ext) => { + html += `
  • ${ext.name}
  • ` + }); + list.innerHTML = html + element.parentNode.appendChild(list) + } else { + element.parentNode.parentNode.removeChild(element.parentNode) + } +} diff --git a/styles/documentation.css b/styles/documentation.css index 996b8ac48f..1b1e543f07 100644 --- a/styles/documentation.css +++ b/styles/documentation.css @@ -112,6 +112,9 @@ nav.app-nav { align-items: center; padding: 0; } +.app-nav #extensions-links + ul a { + text-transform: capitalize; +} .app-nav li { height: var(--nav-height); align-items: center; diff --git a/templates/documentation.twig b/templates/documentation.twig index 1dd1297bcd..d18ccb0787 100644 --- a/templates/documentation.twig +++ b/templates/documentation.twig @@ -12,9 +12,10 @@