Repository navigation
Replies: 1 comment
|
Move the output-path mapping to For the physical files in your example, this is one explicit mapping for a MkDocs 1.6.1 production build: # hooks_prod.py
from mkdocs.structure.files import File
OUTPUTS = {
'procedure_prod.md': 'procedure/index.html',
'Common Folder Name/procedure_prod.md':
'Common Folder Name/procedure/index.html',
}
def on_files(files, config):
for old in list(files):
destination = OUTPUTS.get(old.src_uri)
if destination is None:
continue
replacement = File(
old.src_uri,
old.src_dir,
old.dest_dir,
old.use_directory_urls,
dest_uri=destination,
inclusion=old.inclusion,
)
files.remove(old)
files.append(replacement)
return filesIn the production config: use_directory_urls: true
hooks:
- hooks_prod.pyLeave Markdown links and Using a new Use a corresponding development mapping in the development config, and exclude the other audience's variant from each build so two sources cannot target the same output. Shared files can retain their normal names. This changes the URL mapping without globally replacing The files event is intended for this stage of file manipulation. If you also edit Markdown in a page hook, remember to return the modified string; assigning a local |
Uh oh!
There was an error while loading. Please reload this page.
Hello all, I am trying to figure out how to manage two sites of documentation that share the same purpose but for different audiences: production and development into one branch.
Thank you for your help in advance! Any help is appreciated.
Problem
I am trying to use hooks to change the in-text links to refer to different sources. For prod files, I want them to refer to other prod sources.
I have been able to use the
on_page_markdownReference event to modify default generated URL for prod and dev sitespage.file.name = page.file.name.replace("_prod","")page.file.url = page.file.url.replace("_prod","")page.file.dest_uri = page.file.dest_uri.replace("_prod","")page.file.abs_dest_path = page.file.abs_dest_path.replace("_prod","")prod_site.com/procedure_prodis nowprod_site.com/procedure.My problem is the hooks are not changing the in-text links appropriately to
prod_site.com/procedureinstead ofprod_site.com/procedure_prod. When I click on a link in the page, the link takes me to the latter and not the former so I get a 404 error since the latter does not exist.The in-text link on the markdown files is
[link](procedure_prod.md#section_1)after running the above hook. I even tried replacing the raw markdown content directly when the event was called.markdown = markdown.replace("_prod","")--> this didnt change the resulting html since I checked viaon_page_contentReference event the resultant generated html wasprocedure_prod.htmlinstead ofprocedure.htmlwhich is what I wanted.Context
I have two versions of documentation that I want to publish for the production and development teams maintained on the same branch.
Both sets of documentation share the same purpose and general content. The differences lie in the following
They also share a lot of the same information
This is the current structure
All reactions