-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Clean base * Remove edit btn from a few pages * Update path logic * Add hook to mkdocs * Fix universal edit button functionality and restrict for specific file paths * Refactor edit button URI handling code into a function --------- Co-authored-by: Jeroen Beckers <[email protected]> Co-authored-by: Carlos Holguera <[email protected]>
- Loading branch information
1 parent
b2a3524
commit 1b105b4
Showing
2 changed files
with
47 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,43 @@ | ||
import logging | ||
|
||
log = logging.getLogger('mkdocs') | ||
|
||
def get_edit_url(src_path, edit_url_mastg, edit_url_masvs): | ||
if src_path.startswith("MASVS"): | ||
edit_url = f"{edit_url_masvs}{src_path}" | ||
edit_url = edit_url.replace("master/MASVS/controls", "master/controls/") | ||
edit_url = edit_url.replace("master/MASVS/", "master/Document/") | ||
elif src_path.startswith("MASTG"): | ||
edit_url = f"{edit_url_mastg}{src_path}" | ||
edit_url = edit_url.replace("master/MASTG/0x", "master/Document/0x") | ||
edit_url = edit_url.replace("master/MASTG/", "master/") | ||
elif src_path.startswith("MASWE"): | ||
edit_url = f"{edit_url_mastg}{src_path}" | ||
edit_url = edit_url.replace("master/MASWE/", "master/weaknesses/") | ||
elif src_path.startswith(("contributing", "donate")): | ||
edit_url = f"{edit_url_mastg}{src_path}" | ||
edit_url = edit_url.replace("master/", "master/docs/") | ||
else: | ||
edit_url = "" | ||
|
||
return edit_url | ||
|
||
def on_pre_page(page, config, files): | ||
try: | ||
edit_url_mastg = config["editor_url_mastg"] | ||
edit_url_masvs = config["editor_url_masvs"] | ||
except KeyError: | ||
return page | ||
|
||
src_path = page.file.src_path | ||
|
||
if src_path.startswith(("MASTG", "MASVS", "MASWE", "contributing", "donate")): | ||
edit_url = get_edit_url(src_path, edit_url_mastg, edit_url_masvs) | ||
if edit_url.endswith("/index.md"): | ||
page.edit_url = "" | ||
else: | ||
page.edit_url = edit_url | ||
else: | ||
page.edit_url = "" | ||
|
||
return page |
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