From 1efab909f634ee30506acf3df1d1638321fadc0c Mon Sep 17 00:00:00 2001 From: Carlos Holguera Date: Sun, 7 Jul 2024 10:40:17 +0200 Subject: [PATCH] Update vscode debugging files, add support for tags and datatables (#2653) * add support for tags * add tasks and launch for debugging * remove launch.json from .gitignore * Add DataTables plugin for table functionality replacing tablesort --- .gitignore | 1 - .vscode/launch.json | 28 ++++++++++++++++++++++++++++ .vscode/tasks.json | 27 +++++++++++++++++++++++++++ docs/hooks/add-tags.py | 28 ++++++++++++++++++++++++++++ docs/javascripts/datatables.js | 5 +++++ docs/tags.md | 3 +++ mkdocs.yml | 23 +++++++++++++++++++++-- 7 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 docs/hooks/add-tags.py create mode 100644 docs/javascripts/datatables.js create mode 100644 docs/tags.md diff --git a/.gitignore b/.gitignore index 3a0afa119b..6761eb7320 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,6 @@ logs *.pdf *.docx *.epub -launch.json docs/MASVS/**/ docs/MASVS/*-MASVS-*.md docs/MASTG/**/ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..8952aefe37 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": true + }, + { + "name": "Python: MkDocs Serve", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/.venv/bin/mkdocs", // Adjust the path if mkdocs is not in a virtual environment + "args": ["serve", "-a", "localhost:8002"], + "console": "integratedTerminal", + "env": { + "PYTHONPATH": "${workspaceFolder}/.venv/bin/python3" + }, + "preLaunchTask": "Run populate_dynamic_pages.py" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000000..cb53c57285 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,27 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Run structure_mastg.sh", + "type": "shell", + "command": "./src/scripts/structure_mastg.sh", + "problemMatcher": [] + }, + { + "label": "Run transform_files.py", + "type": "shell", + "command": "${workspaceFolder}/.venv/bin/python", + "args": ["src/scripts/transform_files.py"], + "problemMatcher": [], + "dependsOn": "Run structure_mastg.sh" + }, + { + "label": "Run populate_dynamic_pages.py", + "type": "shell", + "command": "${workspaceFolder}/.venv/bin/python", + "args": ["src/scripts/populate_dynamic_pages.py"], + "problemMatcher": [], + "dependsOn": "Run transform_files.py" + } + ] +} diff --git a/docs/hooks/add-tags.py b/docs/hooks/add-tags.py new file mode 100644 index 0000000000..b7663cf6bb --- /dev/null +++ b/docs/hooks/add-tags.py @@ -0,0 +1,28 @@ +import logging +import mkdocs.plugins + +log = logging.getLogger('mkdocs') + +# https://www.mkdocs.org/dev-guide/plugins/#on_page_markdown +@mkdocs.plugins.event_priority(-50) +def on_page_markdown(markdown, page, **kwargs): + path = page.file.src_uri + + if "MASWE/" in path: + + tags = page.meta.get('tags', []) + + if page.meta.get('platform'): + for platform in page.meta.get('platform', []): + tags.append(platform) + if page.meta.get('profiles'): + for profile in page.meta.get('profiles', []): + tags.append(profile) + + if page.meta.get('masvs-v2'): + for masvs_v2 in page.meta.get('masvs-v2', []): + tags.append(masvs_v2) + + page.meta['tags'] = tags + + return markdown diff --git a/docs/javascripts/datatables.js b/docs/javascripts/datatables.js new file mode 100644 index 0000000000..6c2c75171d --- /dev/null +++ b/docs/javascripts/datatables.js @@ -0,0 +1,5 @@ +document$.subscribe(function() { + $('table').DataTable({ + paging: false + }); +}); diff --git a/docs/tags.md b/docs/tags.md new file mode 100644 index 0000000000..dd6982431d --- /dev/null +++ b/docs/tags.md @@ -0,0 +1,3 @@ +# Tags + + \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index de1388ed98..a02ffa6f5e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -141,6 +141,13 @@ theme: favicon: assets/logo_circle.png icon: repo: fontawesome/brands/github + tag: + android: material/android + ios: material/apple + p: material/eye-circle-outline + l1: material/circle + l2: material/circle-multiple-outline + r: material/circle-double features: - search.suggest - search.share @@ -167,15 +174,19 @@ theme: extra_css: - stylesheets/extra.css + - https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css extra_javascript: - - javascripts/tablesort.min.js - - javascripts/tablesorts.js - javascripts/external_links.js + - https://code.jquery.com/jquery-3.5.1.js + - https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js + - javascripts/datatables.js plugins: # Uses https://github.com/mkdocs/mkdocs-redirects getting the redirects map from src/scripts/generate_redirects.py - search - awesome-pages - mermaid2 + - tags + # tags_file: tags.md # TODO: bug in mkdocs? dynamic tags from hooks not appearing in tags.md markdown_extensions: - meta - toc: @@ -210,6 +221,7 @@ hooks: - docs/hooks/replace_snippets.py - docs/hooks/update_titles.py - docs/hooks/maswe-beta-banner.py + - docs/hooks/add-tags.py extra: generator: false # removed but recreated in copyright above @@ -229,3 +241,10 @@ extra: # - icon: fontawesome/solid/paper-plane # link: mailto:sven.schleier@owasp.org # name: Sven Schleier + tags: + android: android + ios: ios + P: p + L1: l1 + L2: l2 + R: r