18
18
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
19
# IN THE SOFTWARE.
20
20
21
+ import logging
22
+ import sys
23
+
21
24
from collections import defaultdict
22
25
from markdown .extensions .toc import slugify
23
26
from mkdocs import utils
27
+ from mkdocs .commands .build import DuplicateFilter
24
28
from mkdocs .config .config_options import Type
29
+ from mkdocs .exceptions import ConfigurationError
25
30
from mkdocs .plugins import BasePlugin
26
31
27
32
# -----------------------------------------------------------------------------
@@ -59,6 +64,11 @@ def on_nav(self, nav, files, **kwargs):
59
64
file = self .config .get ("tags_file" )
60
65
if file :
61
66
self .tags_file = files .get_file_from_path (file )
67
+ if not self .tags_file :
68
+ log .error (f"Configuration error: { file } doesn't exist." )
69
+ sys .exit ()
70
+
71
+ # Add tags file to files
62
72
files .append (self .tags_file )
63
73
64
74
# Build and render tags index page
@@ -93,7 +103,7 @@ def __render_tag_index(self, markdown):
93
103
94
104
# Render the given tag and links to all pages with occurrences
95
105
def __render_tag_links (self , tag , pages ):
96
- content = ["## <span class=\" md-tag\" >{}</span>" . format ( tag ) , "" ]
106
+ content = [f "## <span class=\" md-tag\" >{ tag } </span>" , "" ]
97
107
for page in pages :
98
108
url = utils .get_relative_url (
99
109
page .file .src_path ,
@@ -113,5 +123,13 @@ def __render_tag(self, tag):
113
123
return dict (name = tag )
114
124
else :
115
125
url = self .tags_file .url
116
- url += "#{}" . format ( self .slugify (tag ))
126
+ url += f "#{ self .slugify (tag )} "
117
127
return dict (name = tag , url = url )
128
+
129
+ # -----------------------------------------------------------------------------
130
+ # Data
131
+ # -----------------------------------------------------------------------------
132
+
133
+ # Set up logging
134
+ log = logging .getLogger ("mkdocs" )
135
+ log .addFilter (DuplicateFilter ())
0 commit comments