From 9af92f65be9afd6911c697c16a62f4b5ddbb4325 Mon Sep 17 00:00:00 2001 From: Will Bamberg Date: Wed, 22 Feb 2023 21:02:53 -0800 Subject: [PATCH] New SVG sidebar --- kumascript/macros/SVGRef.ejs | 313 +++++++++++++---------------------- 1 file changed, 113 insertions(+), 200 deletions(-) diff --git a/kumascript/macros/SVGRef.ejs b/kumascript/macros/SVGRef.ejs index b39a790b5efb..518e5952eb69 100644 --- a/kumascript/macros/SVGRef.ejs +++ b/kumascript/macros/SVGRef.ejs @@ -1,206 +1,119 @@ <% -// Generates and inserts the quicklinks box for the SVG Reference. -// -// Parameters: None. +const locale = env.locale; -var s_svg_href = '/'+env.locale+'/docs/Web/SVG'; -var s_svg_ref_href = '/'+env.locale+'/docs/Web/SVG/Element'; -var s_svg_ref_title = 'SVG Elements'; -switch (env.locale) { - case 'fr': - s_svg_href = '/'+env.locale+'/docs/SVG'; - s_svg_ref_href = '/'+env.locale+'/docs/Web/SVG/Element'; - s_svg_ref_title = 'Éléments SVG'; - break; - default: break; -} - -// Find the section of SVG this page belongs to (that is the first tag of the form "SVG XYZ") -var tags = env.tags; -var foundTag = ''; -if (tags || typeof tags != 'undefined') { - for (const tag of tags) { - if( tag && tag != s_svg_ref_title && tag.substr(0, 4) == 'SVG ') { - foundTag = tag; - break; - } - } -} - -// Find the SVG Tags belonging to the same subject - -var resultSVG = []; -if (foundTag) { - // Find the pages, sub-pages of SVG/Element that are tagged with that specific tag - var pageList = await page.subpagesExpand(s_svg_ref_href); // Get subpages, including tags - - for (aPage of pageList) { - if (page.hasTag(aPage, foundTag)) { - resultSVG.push(aPage.slug.split("/").pop(-1).toLowerCase()); - } - } -} +const text = mdn.localStringMap({ + 'en-US': { + 'Tutorials': 'Tutorials', + 'Reference': 'Reference', + 'Elements': 'Elements', + 'Attributes': 'Attributes', + 'Guides': 'Guides', + 'Introducing SVG from scratch': 'Introducing SVG from scratch' + }, + 'fr': { + 'Tutorials': 'Tutoriels', + 'Reference': 'Références', + 'Elements': 'Éléments', + 'Attributes': 'Attributs', + 'Guides': 'Guides', + }, + 'ja': { + 'Tutorials': 'チュートリアル', + 'Reference': 'リファレンス', + 'Elements': '要素', + }, + 'ko': { + 'Tutorials': '자습서:', + 'Reference': '참고서:', + 'Elements': '요소', + 'Attributes': '속성', + 'Guides': '안내서:', + }, + 'pt-BR': { + 'Tutorials': 'Tutoriais', + 'Reference': 'Referências', + 'Elements': 'Elementos', + 'Attributes': 'Atributos', + 'Guides': 'Guides', + }, + 'ru': { + 'Tutorials': 'Уроки', + 'Reference': 'Справочники', + 'Elements': 'Элементы', + 'Attributes': 'Aтрибуты', + 'Guides': 'Путеводитель', + }, + 'zh-CN': { + 'Tutorials': '教程', + 'Reference': '参考:', + 'Elements': '元素', + 'Attributes': '属性', + 'Guides': '指南:', + }, +}); -var resultAPI = []; +const sidebarURL = `/docs/Web/SVG/`; +const baseURL = `/${env.locale}${sidebarURL}`; -function wrapSVGElement(name) { - return template("SVGElement", [name, "SVGRef"]); +async function getTitle(pageSlug) { + let page = await wiki.getPage(`${baseURL}${pageSlug}`); + if (!page.title) { + page = await wiki.getPage(`/en-US${sidebarURL}${pageSlug}`); + } + return page.title; } -if (s_svg_href) { %> - -<%}%> +%> +