Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions docs/plugins/date-author.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,34 +615,43 @@ You can use this function to retrieve the date and author information for all si
An example of calling the function is shown below:

``` py
from mkdocs_document_dates.utils import load_dates_and_authors
from pathlib import Path
from datetime import datetime

try:
from mkdocs_document_dates.utils import load_dates_and_authors
except ImportError:
load_dates_and_authors = None


def __init__(self):
super().__init__()
self.date_data = {}

# First, call the API in `Global Events` to read data and store it
def on_files(self, files, config):

ddPlugin = config.plugins.get("document-dates")
if ddPlugin:
self.date_data = ddPlugin.data_cached
else:
self.date_data = load_dates_and_authors(Path(config.docs_dir), files)
if load_dates_and_authors is not None:
# If the date plugin is enabled, load the data directly from the plugin; otherwise, get it from the API
dd_plugin = config.plugins.get("document-dates")
if dd_plugin:
self.date_data = dd_plugin.data_cached
else:
self.date_data = load_dates_and_authors(Path(config.docs_dir), files)

# Continue with the original logic

return files

# Then, access the data via the relative path of page.file in `Page Events`
def on_page_markdown(self, markdown, page: Page, config, files):

rel_path = getattr(page.file, 'src_uri')
entry = self.date_data.get(page.file.src_uri, {})

created: datetime = self.date_data[rel_path]['created']
updated: datetime = self.date_data[rel_path]['updated']
created = entry.get("created")
updated = entry.get("updated")

authors = self.date_data[rel_path]['authors']
authors = entry.get("authors", [])
for author in authors:
author.name
author.email
Expand All @@ -660,14 +669,21 @@ def on_page_markdown(self, markdown, page: Page, config, files):
``` py
...

def _parse_date(self, value: str | None, default: datetime | None) -> datetime | None:
if not value:
return default
try:
return datetime.fromisoformat(value).astimezone()
except ValueError:
return default

def on_page_markdown(self, markdown, page: Page, config, files):

created_str = page.meta.get('created')
if created_str:
created: datetime = datetime.fromisoformat(created_str).astimezone()
else:
rel_path = getattr(page.file, 'src_uri')
created: datetime = self.date_data[rel_path]['created']
entry = self.date_data.get(page.file.src_uri, {})

# Overrides default values via meta fields
created = self._parse_date(page.meta.get("created"), entry.get("created"))
updated = self._parse_date(page.meta.get("updated"), entry.get("updated"))

...
```
2 changes: 1 addition & 1 deletion docs/plugins/offline.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Built-in offline plugin
icon: material/connection
icon: lucide/wifi-off
---


Expand Down
2 changes: 1 addition & 1 deletion docs/plugins/optimize.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Built-in optimize plugin
icon: material/rabbit
icon: material/bike-fast
---

# Built-in optimize plugin
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins/search.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Built-in search plugin
icon: octicons/search-24
icon: lucide/search
---

# Built-in search plugin
Expand Down
2 changes: 1 addition & 1 deletion docs/publishing-your-site.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
icon: material/cloud-upload-outline
icon: lucide/cloud-upload
---

# Publishing your site
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/tooltips.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
icon: material/tooltip-plus-outline
icon: material/tooltip-text-outline
---

# Tooltips
Expand Down
26 changes: 24 additions & 2 deletions docs/setup/adding-a-git-repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ automatically requested and rendered.
sorted by update time], the [equivalent API endpoint] is used. So, make sure
you also [create a release for GitLab repositories].

[repo_url]: https://www.mkdocs.org/user-guide/configuration/#repo_url
[repo_url]: https://properdocs.org/user-guide/configuration/#repo_url
[latest release]: https://docs.github.com/en/rest/reference/releases#get-the-latest-release
[create a release]: https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository#creating-a-release
[list of tags sorted by update time]: https://docs.gitlab.com/ee/api/tags.html#list-project-repository-tags
Expand Down Expand Up @@ -160,7 +160,29 @@ theme:
[GitLab]: https://about.gitlab.com/
[Bitbucket]: https://bitbucket.org/
[MkDocs]: https://www.mkdocs.org
[edit_uri]: https://www.mkdocs.org/user-guide/configuration/#edit_uri
[edit_uri]: https://properdocs.org/user-guide/configuration/#edit_uri

#### Markdown for AI agents

<!-- md:version 10.1.5 -->
<!-- md:feature -->

Now, GEO (*SEO applied to AI agents*) is becoming an important stake for websites discoverability.
To allow AI agents (Claude Code, ChatGPT, etc.) to access pages more effectively, you can use the following configuration to let AI agents directly fetch the page Markdown source.

This provides AI with well-structured content, **reduces token consumption by over 80%**, and greatly cuts down irrelevant noise.

``` yaml
theme:
features:
- content.action.agents
```

!!! warning "Note"
- This feature relies on the [`repo_url`][repo_url]{target="_blank"} and [`edit_uri`][edit_uri]{target="_blank"} settings, you need to configure both properties correctly
- If the default branch of your GitHub repository is `main`, add the configuration: `edit_uri: edit/main/docs/`

Related introduction: [Introducing Markdown for Agents](https://blog.cloudflare.com/zh-cn/markdown-for-agents/){target="_blank"}

### Document dates & authors

Expand Down
2 changes: 1 addition & 1 deletion docs/setup/adding-document-dates-authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ show_author: text
---
```

!!! tip "Note"
!!! warning "Note"

When used in combination, the global toggle acts as the master switch, and the local toggle only takes effect when the master switch is enabled. This does not follow the logic of local configurations overriding global ones.

Expand Down
2 changes: 1 addition & 1 deletion docs/setup/setting-up-navigation.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
icon: material/navigation-variant-outline
icon: lucide/panel-left
---

# Setting up navigation
Expand Down
8 changes: 8 additions & 0 deletions material/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
<link rel="alternate" type="application/rss+xml" title="{{ lang.t('rss.created') }}" href="{{ 'feed_rss_created.xml' | url }}">
<link rel="alternate" type="application/rss+xml" title="{{ lang.t('rss.updated') }}" href="{{ 'feed_rss_updated.xml' | url }}">
{% endif %}
{% if "content.action.agents" in config.theme.features and page.edit_url %}
{% if "/blob/" in page.edit_url %}
{% set part = "blob" %}
{% else %}
{% set part = "edit" %}
{% endif %}
<link rel="alternate" type="text/markdown" href="{{ page.edit_url | replace(part, 'raw') }}">
{% endif %}
{% if config.theme.favicon %}
{# 1. Try to capture the bundled icon if it exists #}
{% set svg_raw %}
Expand Down
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ site_description: >-

repo_name: jaywhj/mkdocs-materialx
repo_url: https://github.com/jaywhj/mkdocs-materialx
edit_uri: edit/main/docs/

copyright: Copyright &copy; 2016 - 2026 Aaron Wang

Expand Down Expand Up @@ -38,6 +39,7 @@ theme:
features:
- content.action.edit
- content.action.view
- content.action.agents
- content.code.annotate
- content.code.copy
# - content.code.select
Expand Down
14 changes: 14 additions & 0 deletions src/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
/>
{% endif %}

<!-- Markdown for Agents -->
{% if "content.action.agents" in config.theme.features and page.edit_url %}
{% if "/blob/" in page.edit_url %}
{% set part = "blob" %}
{% else %}
{% set part = "edit" %}
{% endif %}
<link
rel="alternate"
type="text/markdown"
href="{{ page.edit_url | replace(part, 'raw') }}"
/>
{% endif %}

<!-- Favicon -->
{% if config.theme.favicon %}
{# 1. Try to capture the bundled icon if it exists #}
Expand Down