docs(fundamentals): display icons in 'frequent app functions' page#1484
docs(fundamentals): display icons in 'frequent app functions' page#1484
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds the necessary configuration to display icons in the documentation, which involves including the Siemens Element icon CSS and adding some helper classes. The changes are generally good, but I've identified an opportunity to improve the robustness of how the icon CSS file path is resolved in plugin.py. My feedback includes a specific suggestion to make the path resolution more dynamic and less dependent on the execution environment's current working directory.
|
|
||
| def on_files(self, files: Files, config: Config): | ||
| files.append(File('docs-builder.css', dirname(__file__), config.get('site_dir'), config.get('use_directory_urls'))) | ||
| files.append(File('siemens-element-icons.min.css', './node_modules/@siemens/element-icons/dist/style/', config.get('site_dir'), config.get('use_directory_urls'))) |
There was a problem hiding this comment.
The hardcoded relative path './node_modules/...' is brittle because it relies on the current working directory. While mkdocs typically changes the CWD to the project's root directory, this can be unreliable in different execution environments or with different mkdocs invocation methods.
For better robustness and consistency with other parts of this project (e.g., index.mjs), I recommend dynamically locating the node_modules directory by traversing up the file system. This makes the plugin more resilient.
You could replace the current line with logic like this:
# Find node_modules directory by traversing up from the current working directory
path = os.getcwd()
nm_path = None
for _ in range(10): # Limit search depth to 10 levels
if os.path.isdir(os.path.join(path, 'node_modules')):
nm_path = os.path.join(path, 'node_modules')
break
parent = os.path.dirname(path)
if parent == path: # Reached root
break
path = parent
if not nm_path:
raise FileNotFoundError("Could not find 'node_modules' directory.")
icon_css_src_dir = os.path.join(nm_path, '@siemens/element-icons/dist/style/')
files.append(File('siemens-element-icons.min.css', icon_css_src_dir, config.get('site_dir'), config.get('use_directory_urls')))|
Documentation. Coverage Reports: |
175fa6a to
8045af1
Compare
8045af1 to
91dbfde
Compare
spike-rabbit
left a comment
There was a problem hiding this comment.
Instead of loading it for every file, please just load it into the affected one.
We already have the style symlinked into the docs.
So just adding <link rel="stylesheet" href="_src/siemens-element-icons.min.css" /> should be enough.
When we finally have the live-preview as a web-component, we can maybe start adding this globally.
fixes #1444