From 4ea18ddc15ec28f3e884f448ea5e5b05a04f6cc8 Mon Sep 17 00:00:00 2001 From: Guillaume Giudicelli Date: Sat, 30 Sep 2023 16:55:13 -0600 Subject: [PATCH 1/2] Use the translator to find relative paths for tagged pages refs #25387 fix a typo --- .../fluidproperties/FlinakFluidProperties.md | 2 +- python/MooseDocs/extensions/tagging.py | 34 +++++++++++++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/modules/fluid_properties/doc/content/source/fluidproperties/FlinakFluidProperties.md b/modules/fluid_properties/doc/content/source/fluidproperties/FlinakFluidProperties.md index 000dec1a2fd3..1ca1e679b71a 100644 --- a/modules/fluid_properties/doc/content/source/fluidproperties/FlinakFluidProperties.md +++ b/modules/fluid_properties/doc/content/source/fluidproperties/FlinakFluidProperties.md @@ -15,7 +15,7 @@ assumed to be 1.7324e-7 kg/m$^3$/Pa [!cite](richard), but this may be set to a user-defined value. Slightly increasing the partial derivative of density with respect to pressure may improve convergence of compressible flow equations without significantly affecting the physical accuracy of the density estimation -[!cite](scarlat). In the absense of the pressure dependence, the uncertainty +[!cite](scarlat). In the absence of the pressure dependence, the uncertainty on density is $\pm$2% [!cite](richard). Viscosity, isobaric specific heat, and thermal conductivity are calculated diff --git a/python/MooseDocs/extensions/tagging.py b/python/MooseDocs/extensions/tagging.py index b789a10307d8..64523d5a3c8d 100644 --- a/python/MooseDocs/extensions/tagging.py +++ b/python/MooseDocs/extensions/tagging.py @@ -102,15 +102,36 @@ def postExecute(self): if (entry == 'path'): path_value = tag_dict_str.split("path: ")[1].split(',')[0].replace("'", "") + # splitting the path is dangerous, even at content/, as more than one tagged page could have + # the same name. if 'content/' in path_value: - # splitting at content is dangerous, same named pages within two different modules/xxx/doc/content - # could be mixed together - path_value = path_value.split('content/')[1] - - # Use a single / to indicate that it's a local link - link_value = '/' + path_value.replace('.md', '.html') + path_value_cut = path_value.split('content/')[1] + else: + path_value_cut = path_value.split('/')[-1] + + # Find the relative path from the filter page (assumed at filter/index.html) + # Check that there is no ambiguity + target_page = self.translator.findPages(path_value_cut) + filter_page = self.translator.findPages("filter/index.html") + if len(target_page) != 1: + LOG.warning(str(len(target_page)) + " pages found after truncating address when " + "tagging for page initially at address: " + path_value) + if len(filter_page) != 1: + LOG.warning(str(len(filter_page)) + " pages have been found for the filter page " + "when building tagged pages relative links") + # we did not find the pages, cannot search for their relative path + # do the next best thing + if (len(target_page) == 0 or len(filter_page) == 0): + link_value = '/' + path_value_cut.replace('.md', '.html') + else: + target_page = target_page[0] + filter_page = filter_page[0] + link_value = target_page.relativeDestination(filter_page) + + # Insert the link into the dictionary string index = tag_dict_str.find(', key_vals') tag_dict_str = tag_dict_str[:index] + ', link: "' + link_value + '"' + tag_dict_str[index:] + tag_dict_str=re.sub("'",'"', tag_dict_str) # Downstream js cannot handle double quotes tag_dict_str=re.sub("\"\"",'"', tag_dict_str) @@ -119,6 +140,7 @@ def postExecute(self): else: replace_str += "," + tag_dict_str + # Replace the dummy tag dictionary in the JS file with the collected dictionary from parsing the pages replace_str = "{data:[" + replace_str + "]}" # Find the javascript file with error checking From 2906b0514b100fdaf65be099b7635a5368195826 Mon Sep 17 00:00:00 2001 From: Guillaume Giudicelli Date: Mon, 2 Oct 2023 02:09:57 -0600 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Casey Icenhour --- python/MooseDocs/extensions/tagging.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/MooseDocs/extensions/tagging.py b/python/MooseDocs/extensions/tagging.py index 64523d5a3c8d..e0087222c284 100644 --- a/python/MooseDocs/extensions/tagging.py +++ b/python/MooseDocs/extensions/tagging.py @@ -114,13 +114,13 @@ def postExecute(self): target_page = self.translator.findPages(path_value_cut) filter_page = self.translator.findPages("filter/index.html") if len(target_page) != 1: - LOG.warning(str(len(target_page)) + " pages found after truncating address when " - "tagging for page initially at address: " + path_value) + LOG.error(str(len(target_page)) + " pages found after truncating address when " + "tagging for page initially at address: " + path_value) if len(filter_page) != 1: LOG.warning(str(len(filter_page)) + " pages have been found for the filter page " - "when building tagged pages relative links") - # we did not find the pages, cannot search for their relative path - # do the next best thing + "when building relative links for tagged pages!") + # We did not find the pages, thus cannot search for their relative path + # So we simply take the full path value and use it to create the link if (len(target_page) == 0 or len(filter_page) == 0): link_value = '/' + path_value_cut.replace('.md', '.html') else: