Skip to content

Commit bd4245c

Browse files
committed
Add version and feature badges
1 parent f5ec391 commit bd4245c

File tree

3 files changed

+201
-11
lines changed

3 files changed

+201
-11
lines changed

docs/collectors.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ To enable or disable any of the collectors, set the configuration to `true` or `
8989

9090
### QueryCollector
9191

92+
<!-- md:version v1.0 -->
93+
<!-- md:feature collectors.db -->
94+
9295
The Query Collector has the following features
9396
- Show the executed queries including timing
9497
- Show/mark duplicate queries
@@ -104,6 +107,8 @@ The Query Collector has the following features
104107

105108
![Query Collector](img/queries.png)
106109

110+
<details><summary>config/debugbar.php</summary>
111+
107112
```php
108113
'options' => [
109114
// ...
@@ -129,10 +134,12 @@ The Query Collector has the following features
129134
// ...
130135
],
131136
```
137+
</details>
132138

133139
#### On-demand query EXPLAIN
134140

135141
<!-- md:version v3.14.0 -->
142+
<!-- md:feature options.db.explain -->
136143
<!-- md:flag experimental -->
137144

138145
Enable the `options.db.explain` option to run on-demand EXPLAIN queries for any SELECT query in the Debugbar.

docs/features.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,22 @@ If your working in a remote host or docker, you can change the mapping between r
143143

144144
```
145145

146-
</details>
146+
</details>
147+
148+
## Configuraton
149+
150+
### Custom features { #custom }
151+
152+
Custom features or collectors are not enabled by default, but can be enabled by enabling the configuration setting.
153+
This is usually because the target audience of a feature is not large enough.
154+
155+
### Configurable options { #config }
156+
157+
Configurable features are not enabled by default, but can be enabled. This is usually because the target audience of a feature is not large enough.
158+
You can enable the feature by changing the mentioned value in [config/debugbar.php](https://github.com/barryvdh/laravel-debugbar/blob/master/config/debugbar.php) after [publishing the config](installation.md#publish-config).
159+
160+
### Experimental Features { #experimental }
161+
162+
Some features are marked as 'Experimental'. This mostly means the feature is new and not enabled by default, but might become enable by default in the future.
163+
You are welcome to test this feature and report any issues.
164+

docs/overrides/shortcodes.py

Lines changed: 175 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
## File based on https://github.com/processone/docs.ejabberd.im/blob/master/shortcodes.py and
2-
## https://github.com/squidfunk/mkdocs-material/tree/master/material/overrides/hooks
3-
41
# Copyright (c) 2016-2024 Martin Donath <martin.donath@squidfunk.com>
2+
# Copy from https://github.com/squidfunk/mkdocs-material/blob/master/src/overrides/hooks/shortcodes.py
53

64
# Permission is hereby granted, free of charge, to any person obtaining a copy
75
# of this software and associated documentation files (the "Software"), to
@@ -45,8 +43,23 @@ def replace(match: Match):
4543
type, args = match.groups()
4644
args = args.strip()
4745
if type == "version":
46+
if args.startswith("insiders-"):
47+
return _badge_for_version_insiders(args, page, files)
48+
else:
4849
return _badge_for_version(args, page, files)
50+
elif type == "sponsors": return _badge_for_sponsors(page, files)
4951
elif type == "flag": return flag(args, page, files)
52+
elif type == "option": return option(args)
53+
elif type == "setting": return setting(args)
54+
elif type == "feature": return _badge_for_feature(args, page, files)
55+
elif type == "plugin": return _badge_for_plugin(args, page, files)
56+
elif type == "extension": return _badge_for_extension(args, page, files)
57+
elif type == "utility": return _badge_for_utility(args, page, files)
58+
elif type == "example": return _badge_for_example(args, page, files)
59+
elif type == "default":
60+
if args == "none": return _badge_for_default_none(page, files)
61+
elif args == "computed": return _badge_for_default_computed(page, files)
62+
else: return _badge_for_default(args, page, files)
5063

5164
# Otherwise, raise an error
5265
raise RuntimeError(f"Unknown shortcode: {type}")
@@ -58,13 +71,46 @@ def replace(match: Match):
5871
)
5972

6073
# -----------------------------------------------------------------------------
74+
# Helper functions
75+
# -----------------------------------------------------------------------------
76+
6177
# Create a flag of a specific type
6278
def flag(args: str, page: Page, files: Files):
6379
type, *_ = args.split(" ", 1)
6480
if type == "experimental": return _badge_for_experimental(page, files)
65-
81+
elif type == "required": return _badge_for_required(page, files)
82+
elif type == "customization": return _badge_for_customization(page, files)
83+
elif type == "metadata": return _badge_for_metadata(page, files)
84+
elif type == "multiple": return _badge_for_multiple(page, files)
6685
raise RuntimeError(f"Unknown type: {type}")
6786

87+
# Create a linkable option
88+
def option(type: str):
89+
_, *_, name = re.split(r"[.:]", type)
90+
return f"[`{name}`](#+{type}){{ #+{type} }}\n\n"
91+
92+
# Create a linkable setting - @todo append them to the bottom of the page
93+
def setting(type: str):
94+
_, *_, name = re.split(r"[.*]", type)
95+
return f"`{name}` {{ #{type} }}\n\n[{type}]: #{type}\n\n"
96+
97+
# -----------------------------------------------------------------------------
98+
99+
# Resolve path of file relative to given page - the posixpath always includes
100+
# one additional level of `..` which we need to remove
101+
def _resolve_path(path: str, page: Page, files: Files):
102+
path, anchor, *_ = f"{path}#".split("#")
103+
path = _resolve(files.get_file_from_path(path), page)
104+
return "#".join([path, anchor]) if anchor else path
105+
106+
# Resolve path of file relative to given page - the posixpath always includes
107+
# one additional level of `..` which we need to remove
108+
def _resolve(file: File, page: Page):
109+
path = posixpath.relpath(file.src_uri, page.file.src_uri)
110+
return posixpath.sep.join(path.split(posixpath.sep)[1:])
111+
112+
# -----------------------------------------------------------------------------
113+
68114
# Create badge
69115
def _badge(icon: str, text: str = "", type: str = ""):
70116
classes = f"mdx-badge mdx-badge--{type}" if type else "mdx-badge"
@@ -75,6 +121,14 @@ def _badge(icon: str, text: str = "", type: str = ""):
75121
f"</span>",
76122
])
77123

124+
# Create sponsors badge
125+
def _badge_for_sponsors(page: Page, files: Files):
126+
icon = "material-heart"
127+
href = _resolve_path("features.md", page, files)
128+
return _badge(
129+
icon = f"[:{icon}:]({href} 'Sponsors only')",
130+
type = "heart"
131+
)
78132

79133
# Create badge for version
80134
def _badge_for_version(text: str, page: Page, files: Files):
@@ -83,24 +137,135 @@ def _badge_for_version(text: str, page: Page, files: Files):
83137

84138
# Return badge
85139
icon = "material-tag-outline"
140+
href = f"{path}"
141+
return _badge(
142+
icon = f"[:{icon}:]({href} 'Minimum version')",
143+
text = f"[{text}]({path})" if spec else ""
144+
)
145+
146+
# Create badge for feature
147+
def _badge_for_feature(text: str, page: Page, files: Files):
148+
icon = "material-toggle-switch"
149+
href = _resolve_path("features.md#config", page, files)
150+
return _badge(
151+
icon = f"[:{icon}:]({href} 'Configurable feature')",
152+
text = text
153+
)
154+
155+
# Create badge for plugin
156+
def _badge_for_plugin(text: str, page: Page, files: Files):
157+
icon = "material-floppy"
158+
href = _resolve_path("features.md#plugin", page, files)
159+
return _badge(
160+
icon = f"[:{icon}:]({href} 'Plugin')",
161+
text = text
162+
)
163+
164+
# Create badge for extension
165+
def _badge_for_extension(text: str, page: Page, files: Files):
166+
icon = "material-language-markdown"
167+
href = _resolve_path("features.md#extension", page, files)
168+
return _badge(
169+
icon = f"[:{icon}:]({href} 'Markdown extension')",
170+
text = text
171+
)
172+
173+
# Create badge for utility
174+
def _badge_for_utility(text: str, page: Page, files: Files):
175+
icon = "material-package-variant"
176+
href = _resolve_path("features.md#utility", page, files)
177+
return _badge(
178+
icon = f"[:{icon}:]({href} 'Third-party utility')",
179+
text = text
180+
)
181+
182+
# Create badge for example
183+
def _badge_for_example(text: str, page: Page, files: Files):
184+
return "\n".join([
185+
_badge_for_example_download(text, page, files),
186+
_badge_for_example_view(text, page, files)
187+
])
188+
189+
# Create badge for example view
190+
def _badge_for_example_view(text: str, page: Page, files: Files):
191+
icon = "material-folder-eye"
192+
href = f"https://mkdocs-material.github.io/examples/{text}/"
86193
return _badge(
87-
icon = f"[:{icon}:]({path} 'Minimum version')",
88-
text = f"{text}" if spec else ""
194+
icon = f"[:{icon}:]({href} 'View example')",
195+
type = "right"
196+
)
197+
198+
# Create badge for example download
199+
def _badge_for_example_download(text: str, page: Page, files: Files):
200+
icon = "material-folder-download"
201+
href = f"https://mkdocs-material.github.io/examples/{text}.zip"
202+
return _badge(
203+
icon = f"[:{icon}:]({href} 'Download example')",
204+
text = f"[`.zip`]({href})",
205+
type = "right"
89206
)
90207

91208
# Create badge for default value
92209
def _badge_for_default(text: str, page: Page, files: Files):
93210
icon = "material-water"
211+
href = _resolve_path("features.md#default", page, files)
94212
return _badge(
95-
icon = f"[:{icon}:]('Default value')",
213+
icon = f"[:{icon}:]({href} 'Default value')",
96214
text = text
97215
)
98216

217+
# Create badge for empty default value
218+
def _badge_for_default_none(page: Page, files: Files):
219+
icon = "material-water-outline"
220+
href = _resolve_path("features.md#default", page, files)
221+
return _badge(
222+
icon = f"[:{icon}:]({href} 'Default value is empty')"
223+
)
224+
225+
# Create badge for computed default value
226+
def _badge_for_default_computed(page: Page, files: Files):
227+
icon = "material-water-check"
228+
href = _resolve_path("features.md#default", page, files)
229+
return _badge(
230+
icon = f"[:{icon}:]({href} 'Default value is computed')"
231+
)
232+
233+
# Create badge for metadata property flag
234+
def _badge_for_metadata(page: Page, files: Files):
235+
icon = "material-list-box-outline"
236+
href = _resolve_path("features.md#metadata", page, files)
237+
return _badge(
238+
icon = f"[:{icon}:]({href} 'Metadata property')"
239+
)
240+
241+
# Create badge for required value flag
242+
def _badge_for_required(page: Page, files: Files):
243+
icon = "material-alert"
244+
href = _resolve_path("features.md#required", page, files)
245+
return _badge(
246+
icon = f"[:{icon}:]({href} 'Required value')"
247+
)
248+
249+
# Create badge for customization flag
250+
def _badge_for_customization(page: Page, files: Files):
251+
icon = "material-brush-variant"
252+
href = _resolve_path("features.md#custom", page, files)
253+
return _badge(
254+
icon = f"[:{icon}:]({href} 'Customization')"
255+
)
256+
257+
# Create badge for multiple instance flag
258+
def _badge_for_multiple(page: Page, files: Files):
259+
icon = "material-inbox-multiple"
260+
href = _resolve_path("features.md#experimental", page, files)
261+
return _badge(
262+
icon = f"[:{icon}:]({href} 'Multiple instances')"
263+
)
99264

100265
# Create badge for experimental flag
101266
def _badge_for_experimental(page: Page, files: Files):
102267
icon = "material-flask-outline"
268+
href = _resolve_path("features.md#experimental-features", page, files)
103269
return _badge(
104-
icon = f"[:{icon}:]('Experimental')",
105-
text = f"Experimental"
106-
)
270+
icon = f"[:{icon}:]({href} 'Experimental')"
271+
)

0 commit comments

Comments
 (0)