mkdocs 2.0.dev3__py3-none-any.whl → 2.0.dev4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mkdocs/__version__.py CHANGED
@@ -1,2 +1,2 @@
1
1
  __title__ = "mkdocs"
2
- __version__ = "2.0.dev3"
2
+ __version__ = "2.0.dev4"
@@ -34,7 +34,7 @@ class URLProcessor(markdown.treeprocessors.Treeprocessor):
34
34
  path_from = page.path
35
35
  path_to = os.path.normpath(path_from.parent.joinpath(url.path))
36
36
 
37
- target = site.lookup.get(path_to)
37
+ target = site.lookup_by_path(path_to)
38
38
  if target is None:
39
39
  continue # Broken link!
40
40
 
mkdocs/mkdocs.py CHANGED
@@ -20,7 +20,7 @@ RESET = '\033[0m'
20
20
  # The build context is used to ensure the current page and the site index
21
21
  # are available to the RelativeURLs markdown extension.
22
22
  _current_page = contextvars.ContextVar('current_page')
23
- _site_index = contextvars.ContextVar('site_index')
23
+ _site = contextvars.ContextVar('site')
24
24
 
25
25
 
26
26
  def get_current_page():
@@ -31,7 +31,7 @@ def get_current_page():
31
31
 
32
32
 
33
33
  def get_site():
34
- ctx = _site_index.get()
34
+ ctx = _site.get()
35
35
  if ctx is None:
36
36
  raise RuntimeError("No current context")
37
37
  return ctx
@@ -64,13 +64,19 @@ class Site:
64
64
  self._pages = pages
65
65
  self._statics = statics
66
66
 
67
- self.lookup = {
67
+ self._paths = {
68
68
  str(resource.path): resource for resource in pages + statics
69
69
  }
70
- self.lookup_by_url = {
70
+ self._urls = {
71
71
  str(resource.url): resource for resource in pages + statics
72
72
  }
73
73
 
74
+ def lookup_by_path(self, path) -> Page | Static | None:
75
+ return self._paths.get(path)
76
+
77
+ def lookup_by_url(self, url) -> Page | Static | None:
78
+ return self._urls.get(url)
79
+
74
80
  @property
75
81
  def pages(self) -> list[Page]:
76
82
  return list(self._pages)
@@ -93,6 +99,26 @@ class TableOfContents:
93
99
  return bool(self._items)
94
100
 
95
101
 
102
+ class NavItem:
103
+ def __init__(self, title: str, page: Page):
104
+ self.title = title
105
+ self.page = page
106
+
107
+
108
+ class Navigation:
109
+ def __init__(self, nav_items):
110
+ self._items = nav_items
111
+
112
+ def __iter__(self):
113
+ return iter(self._items)
114
+
115
+ @property
116
+ def html(self):
117
+ page = get_current_page()
118
+ t = jinja2.Template("""<ul>{% for item in nav %}<li><a href="{{ item.page.url }}" {% if item.page == page %}class="active"{% endif %}>{{ item.title }}</a></li>{% endfor %}</ul>""")
119
+ return t.render({"nav": self, "page": page})
120
+
121
+
96
122
  class PageContext:
97
123
  def __init__(self, page, text, html, toc):
98
124
  self.path = page.path
@@ -110,7 +136,8 @@ class PageContext:
110
136
 
111
137
  class MkDocs:
112
138
  def __init__(self, input_dir):
113
- self.site_index = self.load_site(input_dir)
139
+ self.site = self.load_site(input_dir)
140
+ self.nav = self.load_nav({}, self.site)
114
141
  self.env = self.init_env(input_dir)
115
142
  self.md = self.init_md()
116
143
  self.base = self.env.get_template('base.html')
@@ -140,6 +167,29 @@ class MkDocs:
140
167
  statics = sorted(statics, key=lambda x: x.url)
141
168
  return Site(pages, statics)
142
169
 
170
+ def load_nav(self, config, site):
171
+ if not config:
172
+ config = {"nav": [
173
+ {"title": page.path.stem, "path": str(page.path)}
174
+ for page in site.pages
175
+ ]}
176
+
177
+ nav_config = config.get('nav', [])
178
+ nav_config = nav_config if isinstance(nav_config, list) else []
179
+ nav_items = []
180
+ for item in nav_config:
181
+ if not isinstance(item, dict):
182
+ continue
183
+ path = item.get('path', '')
184
+ title = item.get('title', '')
185
+ if not path:
186
+ continue
187
+ if path:
188
+ page = site.lookup_by_path(path)
189
+ nav_item = NavItem(title, page)
190
+ nav_items.append(nav_item)
191
+ return Navigation(nav_items)
192
+
143
193
  def init_env(self, input_dir) -> jinja2.Environment:
144
194
  @jinja2.pass_context
145
195
  def url(ctx, url_to):
@@ -178,19 +228,21 @@ class MkDocs:
178
228
  @contextlib.contextmanager
179
229
  def set_context(self, current_page):
180
230
  token_page = _current_page.set(current_page)
181
- token_site = _site_index.set(self.site_index)
231
+ token_site = _site.set(self.site)
182
232
  try:
183
233
  yield
184
234
  finally:
185
235
  _current_page.reset(token_page)
186
- _site_index.reset(token_site)
236
+ _site.reset(token_site)
237
+
238
+ # Commands...
187
239
 
188
240
  def build(self, input, output):
189
241
  input_dir = pathlib.Path(input)
190
242
  output_dir = pathlib.Path(output)
191
243
 
192
- print(DARK_GRAY + "Collected %d resources" % len(self.site_index) + RESET)
193
- for page in self.site_index.pages:
244
+ print(DARK_GRAY + "Collected %d resources" % len(self.site) + RESET)
245
+ for page in self.site.pages:
194
246
  print(GREEN + " + " + RESET + BOLD + str(page.path) + RESET + DARK_GRAY + " [markdown]" + RESET)
195
247
  input_path = input_dir.joinpath(page.path)
196
248
  output_path = output_dir.joinpath(page.build_path)
@@ -200,12 +252,12 @@ class MkDocs:
200
252
  html = self.md.reset().convert(text)
201
253
  toc = TableOfContents(self.md)
202
254
  page_ctx = PageContext(page=page, text=text, html=html, toc=toc)
203
- output = self.base.render(page=page_ctx)
255
+ output = self.base.render(page=page_ctx, nav=self.nav)
204
256
 
205
257
  output_path.parent.mkdir(parents=True, exist_ok=True)
206
258
  output_path.write_text(output)
207
259
 
208
- for static in self.site_index.statics:
260
+ for static in self.site.statics:
209
261
  print(GREEN + " + " + RESET + BOLD + str(static.path) + RESET + DARK_GRAY + " [static]" + RESET)
210
262
  input_path = input_dir.joinpath(static.path)
211
263
  output_path = output_dir.joinpath(static.path)
@@ -216,15 +268,15 @@ class MkDocs:
216
268
  def serve(self, input):
217
269
  input_dir = pathlib.Path(input)
218
270
 
219
- print(DARK_GRAY + "Serving %d resources" % len(self.site_index) + RESET)
220
- for page in self.site_index.pages:
271
+ print(DARK_GRAY + "Serving %d resources" % len(self.site) + RESET)
272
+ for page in self.site.pages:
221
273
  print(GREEN + " + " + RESET + BOLD + str(page.url) + RESET + DARK_GRAY + " [markdown]" + RESET)
222
- for static in self.site_index.statics:
274
+ for static in self.site.statics:
223
275
  print(GREEN + " + " + RESET + BOLD + str(static.url) + RESET + DARK_GRAY + " [static]" + RESET)
224
276
  print()
225
277
 
226
278
  def app(request):
227
- resource = self.site_index.lookup_by_url.get(request.url.path)
279
+ resource = self.site.lookup_by_url(request.url.path)
228
280
 
229
281
  if isinstance(resource, Page):
230
282
  input_path = input_dir.joinpath(resource.path)
@@ -233,7 +285,7 @@ class MkDocs:
233
285
  html = self.md.reset().convert(text)
234
286
  toc = TableOfContents(self.md)
235
287
  page_ctx = PageContext(page=resource, text=text, html=html, toc=toc)
236
- output = self.base.render(page=page_ctx)
288
+ output = self.base.render(page=page_ctx, nav=self.nav)
237
289
  return httpx.Response(200, content=httpx.HTML(output))
238
290
  elif isinstance(resource, Static):
239
291
  input_path = input_dir.joinpath(resource.path)
@@ -244,6 +296,8 @@ class MkDocs:
244
296
  server.serve()
245
297
 
246
298
 
299
+ # Command line client...
300
+
247
301
  @click.group()
248
302
  def cli():
249
303
  if pathlib.Path('mkdocs.yml').exists():
mkdocs/theme/base.html CHANGED
@@ -43,19 +43,33 @@ main {
43
43
 
44
44
  @media (max-width: 1000px) {
45
45
  main {
46
+ margin-left: 20%;
46
47
  width: 75%;
47
48
  }
48
49
 
49
50
  nav.toc {
50
51
  display: none;
51
52
  }
53
+
54
+ nav.site {
55
+ width: 25%;
56
+ }
52
57
  }
53
58
 
54
- @media (max-width: 600px) {
59
+ @media (max-width: 750px) {
55
60
  main {
61
+ margin-left: 0;
56
62
  width: 100%;
57
63
  padding: 1rem 1.5rem;
58
64
  }
65
+
66
+ nav.toc {
67
+ display: none;
68
+ }
69
+
70
+ nav.site {
71
+ display: none;
72
+ }
59
73
  }
60
74
 
61
75
  /* Typography & spacing */
@@ -168,6 +182,14 @@ a.toclink:hover::after {
168
182
 
169
183
  /* Table of contents styling */
170
184
 
185
+ nav.site {
186
+ position: fixed;
187
+ width : 20%;
188
+ padding: 2rem;
189
+ height: 100%;
190
+ overflow-y: scroll;
191
+ }
192
+
171
193
  nav.toc {
172
194
  position: fixed;
173
195
  margin-left: 80%;
@@ -179,6 +201,35 @@ nav.toc {
179
201
 
180
202
  /* Navigation styling */
181
203
 
204
+ nav.site ul {
205
+ padding: 0;
206
+ margin: 0;
207
+ }
208
+
209
+ nav.site li {
210
+ padding: 0;
211
+ margin: 0.5rem 0;
212
+ display: block;
213
+ }
214
+
215
+ nav.site li a.active {
216
+ color: var(--link-color);
217
+ }
218
+
219
+ nav.site li a:hover {
220
+ color: var(--link-color);
221
+ text-decoration: none;
222
+ }
223
+
224
+ nav.site li a {
225
+ color: var(--muted-fg-color);
226
+ }
227
+
228
+ nav.site li a:hover {
229
+ color: var(--fg-color);
230
+ text-decoration: none;
231
+ }
232
+
182
233
  nav.toc ul {
183
234
  padding: 0;
184
235
  margin: 0;
@@ -210,6 +261,11 @@ nav.toc li a:hover {
210
261
  </style>
211
262
  </head>
212
263
  <body>
264
+ {% if nav %}
265
+ <nav class="site">
266
+ {{ nav.html }}
267
+ </nav>
268
+ {% endif %}
213
269
  {% if page.toc %}
214
270
  <nav class="toc">
215
271
  {{ page.toc.html }}
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.5
2
+ Name: mkdocs
3
+ Version: 2.0.dev4
4
+ Summary: HTTP, for Python.
5
+ Author-email: Kim Christie <noreply@lovelydinosaur.com>
6
+ Classifier: Development Status :: 4 - Beta
7
+ Classifier: Environment :: Web Environment
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Topic :: Internet :: WWW/HTTP
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: click
18
+ Requires-Dist: httpx>=1.0.dev6
19
+ Requires-Dist: jinja2
20
+ Requires-Dist: markdown
21
+ Description-Content-Type: text/markdown
22
+
23
+ # MkDocs
24
+
25
+ MkDocs is a smart, simple, website design tool.
26
+
27
+ Getting started is easy...
28
+
29
+ ```shell
30
+ $ pip install mkdocs --pre
31
+ ```
32
+
33
+ *This will install the version 2.0 pre-release.*
34
+
35
+ ## Getting started
36
+
37
+ 1. Create a `docs/README.md` page.
38
+ 2. Run `mkdocs serve` to view your documentation in a browser.
39
+ 3. Run `mkdocs build` to build a static website ready to host.
40
+
41
+ ## Writing your docs
42
+
43
+ 1. Create additional markdown pages.
44
+ 2. Use relative interlinking between pages.
45
+ 3. Include images and use relative interlinking from pages.
46
+
47
+ *MkDocs supports [GitHub Flavored Markdown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax) for page authoring.*
48
+
49
+ ## Styling your docs
50
+
51
+ 1. Create a `templates/base.html` to customise the styling.
52
+ 2. Include css and javascript to serve static files.
53
+
54
+ *MkDocs uses [Jinja templating](https://jinja.palletsprojects.com/en/stable/templates/) for HTML rendering.*
55
+
56
+ A starting point can be as simple as...
57
+
58
+ ```html
59
+ <html>
60
+ <head>
61
+ <meta charset="utf-8">
62
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
63
+ <title>{{ page.toc.title }}</title>
64
+ <link rel="stylesheet" href="{{ '/css/default.css' | url }}">
65
+ </head>
66
+ <body>
67
+ <main>
68
+ {{ page.html }}
69
+ </main>
70
+ </body>
71
+ </html>
72
+ ```
@@ -0,0 +1,12 @@
1
+ mkdocs/__init__.py,sha256=NwNA-Nxju0I4e1-Msqo_ewJLRcjJjEMiVs2bbfzoMCg,283
2
+ mkdocs/__version__.py,sha256=H32qhExLRVyUqFMfnUmHAtd8VRrtgzXcA5Xgp9BLsUA,46
3
+ mkdocs/mkdocs.py,sha256=xCa3TEcWJM4igJk7J2yo0clYTenwulMTyPpcZlr9bQY,10242
4
+ mkdocs/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ mkdocs/extensions/relative_urls.py,sha256=iVwmxDeXVAP6MvdJkkdhPT3KZY-QskD8fOQAVX1R3e4,1954
6
+ mkdocs/extensions/short_codes.py,sha256=I2SwGMcG9OT_vpkJwPI8cHBTkwQAjSPZmoQKfctsHn4,950
7
+ mkdocs/extensions/strike_thru.py,sha256=GrCbfMrHz_2Vlh3E572EQYOSDzEGym34pkHElzF2HZY,577
8
+ mkdocs/theme/base.html,sha256=tWLme7GnwgJmWFLvkHCHmUYyDobxVqEBgtge47hClXY,4269
9
+ mkdocs-2.0.dev4.dist-info/METADATA,sha256=ZkPn54kDu5kJVRpJlisgu7O0D7kkWp9bwhmMk70vVI4,2151
10
+ mkdocs-2.0.dev4.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
11
+ mkdocs-2.0.dev4.dist-info/entry_points.txt,sha256=5PqBrzYJLZ9-yQ0djvENWOQ-0x6Xj30JYNSzM_m70ZU,38
12
+ mkdocs-2.0.dev4.dist-info/RECORD,,
@@ -1,20 +0,0 @@
1
- Metadata-Version: 2.5
2
- Name: mkdocs
3
- Version: 2.0.dev3
4
- Summary: HTTP, for Python.
5
- Author-email: Kim Christie <noreply@lovelydinosaur.com>
6
- Classifier: Development Status :: 4 - Beta
7
- Classifier: Environment :: Web Environment
8
- Classifier: Intended Audience :: Developers
9
- Classifier: Operating System :: OS Independent
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.10
12
- Classifier: Programming Language :: Python :: 3.11
13
- Classifier: Programming Language :: Python :: 3.12
14
- Classifier: Programming Language :: Python :: 3.13
15
- Classifier: Topic :: Internet :: WWW/HTTP
16
- Requires-Python: >=3.10
17
- Requires-Dist: click
18
- Requires-Dist: httpx>=1.0.dev5
19
- Requires-Dist: jinja2
20
- Requires-Dist: markdown
@@ -1,12 +0,0 @@
1
- mkdocs/__init__.py,sha256=NwNA-Nxju0I4e1-Msqo_ewJLRcjJjEMiVs2bbfzoMCg,283
2
- mkdocs/__version__.py,sha256=y7OAtBTvz302kS_lnppuG9xWGpwIuMUpU4-ayC_CP8A,46
3
- mkdocs/mkdocs.py,sha256=RnJ8wj2vzozAEqD-X5JMxRoP2wi-uWBC8NH7_DF1Slg,8677
4
- mkdocs/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- mkdocs/extensions/relative_urls.py,sha256=woA0EUuCXa10wt6C0VCjYnY7jO-fj-wd9uOVU20D96U,1950
6
- mkdocs/extensions/short_codes.py,sha256=I2SwGMcG9OT_vpkJwPI8cHBTkwQAjSPZmoQKfctsHn4,950
7
- mkdocs/extensions/strike_thru.py,sha256=GrCbfMrHz_2Vlh3E572EQYOSDzEGym34pkHElzF2HZY,577
8
- mkdocs/theme/base.html,sha256=xB9VAAgy6zwucGedwTfdhigwNu_lhY3OKiY4aSsN6ZQ,3471
9
- mkdocs-2.0.dev3.dist-info/METADATA,sha256=KerzpRlQfNrRd1Ocu8w5tpEkXPdEyPNgGWyYJwpfzdU,729
10
- mkdocs-2.0.dev3.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
11
- mkdocs-2.0.dev3.dist-info/entry_points.txt,sha256=5PqBrzYJLZ9-yQ0djvENWOQ-0x6Xj30JYNSzM_m70ZU,38
12
- mkdocs-2.0.dev3.dist-info/RECORD,,