Skip to content

Commit

Permalink
Merge pull request #25636 from GiudGiud/PR_links2
Browse files Browse the repository at this point in the history
Use the translator to find relative paths for tagged pages
  • Loading branch information
cticenhour authored Oct 3, 2023
2 parents 19bec9d + 2906b05 commit d181ad4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 28 additions & 6 deletions python/MooseDocs/extensions/tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.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 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:
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)
Expand All @@ -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
Expand Down

0 comments on commit d181ad4

Please sign in to comment.