From dd191fab2d351dbbf45f01925d602e2c44368823 Mon Sep 17 00:00:00 2001 From: wbamberg Date: Sat, 4 Mar 2023 13:11:17 -0800 Subject: [PATCH] feat(macros): rewrite SVG sidebar (#8289) - Adds sections "Tutorials" and "Guides". - Moves "Elements" under a new section "Reference". - Adds subsection "Attributes" under "Reference". --- kumascript/macros/SVGRef.ejs | 312 +++++++++++++---------------------- 1 file changed, 113 insertions(+), 199 deletions(-) diff --git a/kumascript/macros/SVGRef.ejs b/kumascript/macros/SVGRef.ejs index b4bf451920da..331a5747468f 100644 --- a/kumascript/macros/SVGRef.ejs +++ b/kumascript/macros/SVGRef.ejs @@ -1,206 +1,120 @@ <% -// 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; - } - } -} +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': '指南:', + }, +}); -// Find the SVG Tags belonging to the same subject +const sidebarURL = `/docs/Web/SVG/`; +const baseURL = `/${env.locale}${sidebarURL}`; -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()); - } - } +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; } -var resultAPI = []; - -function wrapSVGElement(name) { - return template("SVGElement", [name, "SVGRef"]); -} +%> + -if (s_svg_href) { %> - -<%}%>