forked from iree-org/iree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom edit URLs to generated website pages. (iree-org#15605)
The MLIR dialect reference pages at https://iree.dev/reference/mlir-dialects/ are generated from a mix of .td (tablegen) files. This fixes the "edit this page" links for those pages to point at valid source locations  For example, https://iree.dev/reference/mlir-dialects/HAL/ now points to https://github.com/openxla/iree/tree/main/compiler/src/iree/compiler/Dialect/HAL/IR instead of https://github.com/openxla/iree/blob/main/docs/website/docs/reference/mlir-dialects/HAL.md (which does not exist)
- Loading branch information
Showing
5 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2023 The IREE Authors | ||
# | ||
# Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
"""Custom edit URL plugin for mkdocs. | ||
MkDocs can create links to view/edit the source of a website page in the | ||
associated source location (e.g. GitHub repository). | ||
* https://www.mkdocs.org/user-guide/configuration/#edit_uri | ||
* https://squidfunk.github.io/mkdocs-material/setup/adding-a-git-repository/#code-actions | ||
For markdown files in the documentation folder, this is a straightforward | ||
process, taking the relative path and appending it to the source location: | ||
/repo_root/docs/section/page.md --> | ||
https://github.com/[org]/[repo]/blob/main/docs/section/page.md | ||
For generated files, the inferred URL does not match the actual source: | ||
/repo_root/src/file.cc --> | ||
/repo_root/docs/gen/file.md --> | ||
[broken link] https://github.com/[org]/[repo]/blob/main/docs/gen/file.md | ||
This plugin allows for pages to explicitly specify their source URL via | ||
markdown frontmatter. | ||
References: | ||
* https://github.com/renovatebot/renovatebot.github.io/pull/187 | ||
* https://github.com/mkdocs/mkdocs/discussions/2757 | ||
Usage: | ||
1. Add a hook to mkdocs.yml by following | ||
https://www.mkdocs.org/user-guide/configuration/#hooks | ||
2. Add frontmatter to any pages you want to customize: | ||
--- | ||
custom_edit_url: [full hyperlink to the source location, e.g. https://github.com/...] | ||
--- | ||
""" | ||
|
||
|
||
def on_page_context(context, page, config, **kwargs): | ||
if "custom_edit_url" in page.meta: | ||
page.edit_url = page.meta["custom_edit_url"] | ||
return context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters