diff --git a/src/plugins/category-listing/index.js b/src/plugins/category-listing/index.js index cb911599d..a4987392a 100644 --- a/src/plugins/category-listing/index.js +++ b/src/plugins/category-listing/index.js @@ -17,8 +17,9 @@ module.exports = async function myPlugin(context, options) { const tagNames = doc.tags.map(t => t.label); const mitigates = (doc.frontMatter.practice?.mitigates ?? []).map(t => t.tag) const attendant = (doc.frontMatter.practice?.attendant ?? []).map(t => t.tag) + const practices = (doc.frontMatter.method?.practices ?? []).map(t => t.tag) - const allTags = [...tagNames, ...mitigates, ...attendant] + const allTags = [...tagNames, ...mitigates, ...attendant, ...practices] //console.log(JSON.stringify(allTags)); diff --git a/src/theme/PracticeIntro/index.js b/src/theme/PracticeIntro/index.js index 79f6c8b0c..ea9d87964 100644 --- a/src/theme/PracticeIntro/index.js +++ b/src/theme/PracticeIntro/index.js @@ -1,6 +1,7 @@ import React from 'react'; import styles from './styles.module.css' import { useDocById } from '@docusaurus/theme-common/internal' +import { usePluginData } from '@docusaurus/useGlobalData' import { useLocation } from '@docusaurus/router'; function formatReadableTag(page) { @@ -17,13 +18,59 @@ const Risk = ({tag, reason}) => { ) } +const Method = ({ article, permalink, reason }) => { + return ( +
  • {article}: {reason}
  • + ) +} -export default ({details}) => { +const Aka = ({ name, from, link }) => { + return ( +
  • {name}{ from ? ( (in {from})): null }
  • + ) +} + + +function isMethod(article, title) { + const matching = (article.frontMatter?.method?.practices ?? []).find(m => m.tag == title); + if (matching) { + return { + article: article.title, + permalink: article.permalink, + reason: matching.reason, + use: matching.use ?? [] + } + } else { + return undefined; + } +} + +function sortAndUnique(l) { + const uniqueArray = l.filter(function(item, pos) { + return l.findIndex(e => e.article == item.article) == pos; + }) + const sorted = uniqueArray.sort((a, b) => a.article.localeCompare(b.article)) + return sorted +} + +export default ({details}) => { + const title = details.title + const pl = useLocation().pathname const stripped = pl.endsWith('/') ? pl+"index" : pl const imageLink = "/img/generated/single/" + stripped + ".png" + const allTags = usePluginData('category-listing'); + + const myTag = allTags[title] + + //console.log("Found " + JSON.stringify(myTag.map(i => i.title))) + + const methods = sortAndUnique(myTag.map(article => isMethod(article, title)).filter(i => i != undefined)) + const mainAka = details.practice.aka.map(i => { return { name: i} }) + const moreAka = methods.flatMap(m => m.use.map(u => { return {name: u, from: m.article, link: m.permalink, bob: JSON.stringify(m) }})) + const sortedAka = [...mainAka, ...moreAka].sort((a, b) => a.name.localeCompare(b.name)) return
    @@ -37,7 +84,8 @@ export default ({details}) => {

    Also Known As

    Related Practices

    @@ -58,5 +106,16 @@ export default ({details}) => { details.practice.attendant.map(i => ) } + { + methods.length > 0 ? ( + <> +

    Used By

    +
      + { + methods.map(i => ) + } +
    + ) : null + }
    } \ No newline at end of file diff --git a/src/theme/PracticeIntro/styles.module.css b/src/theme/PracticeIntro/styles.module.css index e26ef8ebb..755204295 100644 --- a/src/theme/PracticeIntro/styles.module.css +++ b/src/theme/PracticeIntro/styles.module.css @@ -37,4 +37,9 @@ flex-grow: .7; flex-shrink: .5; padding: 1rem; +} + +.methodRef { + color: darkgray; + font-style: italic; } \ No newline at end of file diff --git a/src/theme/RiskIntro/index.js b/src/theme/RiskIntro/index.js index 6a7a5d1bd..f272220f3 100644 --- a/src/theme/RiskIntro/index.js +++ b/src/theme/RiskIntro/index.js @@ -60,7 +60,7 @@ export default ({ fm }) => { const allTags = usePluginData('category-listing'); const myTag = allTags[title] - console.log("Found " + JSON.stringify(myTag.map(i => i.title))) + //console.log("Found " + JSON.stringify(myTag.map(i => i.title))) const mitigating = sortAndUnique(myTag.map(article => isPracticeMitigating(article, title)).filter(i => i != undefined)) const attendant = sortAndUnique(myTag.map(article => isPracticeAttendant(article, title)).filter(i => i != undefined))