1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729
|
---
title: Built-in blog plugin
icon: material/newspaper-variant-outline
---
# Built-in blog plugin
The blog plugin makes it very easy to build a blog, either as a sidecar to
your documentation or as the main thing. Focus on your content while the plugin
does all the heavy lifting, generating a view of all latest posts, [archive] and
[category] pages, configurable [pagination] and much more.
[archive]: #archive
[category]: #categories
[pagination]: #pagination
## Objective
### How it works
The plugin scans the configured [`posts` directory][config.post_dir] for
`.md` files from which paginated views[^1] are automatically generated. If not
configured otherwise, the plugin expects that your project has the following
directory layout, and will create any missing directories or files for you:
[^1]:
Views are pages that are automatically generated, i.e., the entry point to
your blog listing all latest posts, as well as [archive] and [category]
pages that list all posts associated with them through [metadata] in
chronological order.
``` { .sh .no-copy }
.
├─ docs/
│ └─ blog/
│ ├─ posts/
│ └─ index.md
└─ mkdocs.yml
```
The `index.md` file in the [`blog` directory][config.blog_dir] is the entry
point to your blog – a paginated view listing all posts in reverse chronological
order. Besides that, the plugin supports automatically creating [archive] and
[category] pages that list a subset of posts for a time interval or category.
[Post URLs][config.post_url_format] are completely configurable, no matter if
you want your URLs to include the post's date or not. Rendered dates always
display in the locale of the [site language] of your project. Like in other
static blog frameworks, posts can be annotated with a variety of [metadata],
allowing for easy integration with other [built-in plugins], e.g., the
[social] and [tags] plugin.
Posts can be organized in nested folders with a directory layout that suits your
specific needs, and can make use of all components and syntax that Material for
MkDocs offers, including [admonitions], [annotations], [code blocks],
[content tabs], [diagrams], [icons], [math], and more.
[metadata]: #metadata
[built-in plugins]: index.md
[social]: social.md
[tags]: tags.md
[admonitions]: ../reference/admonitions.md
[annotations]: ../reference/annotations.md
[code blocks]: ../reference/code-blocks.md
[content tabs]: ../reference/content-tabs.md
[diagrams]: ../reference/diagrams.md
[icons]: ../reference/icons-emojis.md
[math]: ../reference/math.md
### When to use it
If you want to add a blog to your project, or migrate from another blog
framework to Material for MkDocs because of its excellent technical writing
capabilities, this plugin is a great choice, as it integrates perfectly with
many other built-in plugins:
<div class="grid cards" markdown>
- :material-file-tree: __[Built-in meta plugin][meta]__
---
The meta plugin makes it easy to apply [metadata] to a subset of posts,
including authors, tags, categories, draft status, as well as social card
layouts.
---
__Simpler organization, categorization and management of post metadata__
- :material-share-circle: __[Built-in social plugin][social]__
---
The social plugin automatically generates beautiful and customizable
social cards for each post and page, showing as previews on social media.
---
__Links to your blog render beautiful social cards when shared on social
media__
- :material-rabbit: __[Built-in optimize plugin][optimize]__
---
The optimize plugin automatically identifies and optimizes all media files
that you reference in your project by using compression and conversion
techniques.
---
__Your blog loads faster as smaller images are served to your users__
- :material-tag-text: __[Built-in tags plugin][tags]__
---
The tags plugin allows to categorize posts alongside with pages in your
project, to improve their discoverability and connect posts to your
documentation.
---
__Your documentation's tag system integrates with your blog__
</div>
[meta]: meta.md
[social]: social.md
[optimize]: optimize.md
[tags]: tags.md
## Configuration
<!-- md:version 9.2.0 -->
<!-- md:plugin [blog] – built-in -->
<!-- md:flag multiple -->
<!-- md:flag experimental -->
As with all [built-in plugins], getting started with the blog plugin is
straightforward. Just add the following lines to `mkdocs.yml`, and you can
start writing your first post:
``` yaml
plugins:
- blog
```
The blog plugin is built into Material for MkDocs and doesn't need to be
installed.
[blog]: blog.md
[built-in plugins]: index.md
### Navigation
If you do not have site navigation configured in your `mkdocs.yml` then there is
nothing more to do. The blog [archive] and [category] pages will automatically
appear underneath the automatically generated navigation.
If you do have a navigation structure defined then you will need to specify
where the blog should appear in this. Create a [navigation section with an index
page] for the blog:
```yaml
theme:
name: material
features:
- navigation.indexes
nav:
- ...
- Blog:
- blog/index.md
```
The [archive] and [category] pages will appear within that section as
subsections beneath pages in the blog section. In this case, they would appear
after `index.md`. The path to the `index.md` file must match
[blog_dir][config.blog_dir]. This means that you can name the blog navigation
entry anything you like: 'Blog' or 'News' or perhaps 'Tips'.
[navigation section with an index page]: ../setup/setting-up-navigation.md#section-index-pages
### General
The following settings are available:
---
#### <!-- md:setting config.enabled -->
<!-- md:version 9.2.0 -->
<!-- md:default `true` -->
Use this setting to enable or disable the plugin when [building your project].
It's normally not necessary to specify this setting, but if you want to disable
the plugin, use:
``` yaml
plugins:
- blog:
enabled: false
```
[building your project]: ../creating-your-site.md#building-your-site
---
#### <!-- md:setting config.blog_dir -->
<!-- md:version 9.2.0 -->
<!-- md:default `blog` -->
Use this setting to change the path where your blog is located in the
[`docs` directory][mkdocs.docs_dir]. The path is included in the generated
URLs as a prefix for all posts and views. You can change it with:
=== "Documentation + Blog"
``` yaml
plugins:
- blog:
blog_dir: blog
```
=== "Blog only"
``` yaml
plugins:
- blog:
blog_dir: .
```
The provided path is resolved from the [`docs` directory][mkdocs.docs_dir].
---
#### <!-- md:setting config.blog_toc -->
<!-- md:version 9.2.0 -->
<!-- md:default `false` -->
Use this setting to leverage the table of contents to display post titles in
views. This might be useful, if your post excerpts are rather long. If you want
to enable it, use:
``` yaml
plugins:
- blog:
blog_toc: true
```
### Posts
The following settings are available for posts:
---
#### <!-- md:setting config.post_dir -->
<!-- md:version 9.2.0 -->
<!-- md:default `{blog}/posts` -->
Use this setting to change the folder where your posts are located. It's
normally not necessary to change this setting, but if you want to rename the
folder or change its file system location, use:
``` yaml
plugins:
- blog:
post_dir: "{blog}/articles"
```
Note that the [`posts` directory][config.post_dir] is solely used for post
organization – it is not included in post URLs, since they are automatically
and comfortably generated by this plugin.
The following placeholders are available:
- `blog` – [`blog` directory][config.blog_dir]
The provided path is resolved from the [`docs` directory][mkdocs.docs_dir].
---
#### <!-- md:setting config.post_date_format -->
<!-- md:version 9.2.0 -->
<!-- md:default `long` -->
Use this setting to change the date format of posts. This plugin uses [babel]
to render dates in the configured [site language]. You can use [babel]'s
[pattern syntax] or the following shortcodes:
=== "Monday, January 31, 2024"
``` yaml
plugins:
- blog:
post_date_format: full
```
=== "January 31, 2024"
``` yaml
plugins:
- blog:
post_date_format: long
```
=== "Jan 31, 2024"
``` yaml
plugins:
- blog:
post_date_format: medium
```
=== "1/31/24"
``` yaml
plugins:
- blog:
post_date_format: short
```
Note that depending on the [site language], results might look different for
other languages.
[babel]: https://pypi.org/project/Babel/
[site language]: ../setup/changing-the-language.md#site-language
[pattern syntax]: https://babel.pocoo.org/en/latest/dates.html#pattern-syntax
---
#### <!-- md:setting config.post_url_date_format -->
<!-- md:version 9.2.0 -->
<!-- md:default `yyyy/MM/dd` -->
Use this setting to change the date format used in post URLs. The format string
must adhere to [babel]'s [pattern syntax] and should not contain whitespace.
Some popular choices:
=== ":material-link: blog/2024/01/31/:material-dots-horizontal:/"
``` yaml
plugins:
- blog:
post_url_date_format: yyyy/MM/dd
```
=== ":material-link: blog/2024/01/:material-dots-horizontal:/"
``` yaml
plugins:
- blog:
post_url_date_format: yyyy/MM
```
=== ":material-link: blog/2024/:material-dots-horizontal:/"
``` yaml
plugins:
- blog:
post_url_date_format: yyyy
```
If you want to remove the date from post URLs, e.g., when your blog features
mostly evergreen content, you can remove the `date` placeholder from the
[`post_url_format`][config.post_url_format] format string.
---
#### <!-- md:setting config.post_url_format -->
<!-- md:version 9.2.0 -->
<!-- md:default `{date}/{slug}` -->
Use this setting to change the format string that is used when generating post
URLs. You can freely combine placeholders, and join them with slashes or other
characters:
=== ":material-link: blog/2024/:material-dots-horizontal:/"
``` yaml
plugins:
- blog:
post_url_format: "{date}/{slug}"
```
=== ":material-link: blog/:material-dots-horizontal:/"
``` yaml
plugins:
- blog:
post_url_format: "{slug}"
```
The following placeholders are available:
- `categories` – Post categories, slugified with [`categories_slugify`][config.categories_slugify]
- `date` – Post date, formatted with [`post_url_date_format`][config.post_url_date_format]
- `slug` – Post title, slugified with [`post_slugify`][config.post_slugify], or explicitly set via [`slug`][meta.slug] metadata property
- `file` – Post filename without `.md` file extension
If you remove the `date` placeholder, make sure that post URLs don't collide
with URLs of other pages hosted under the [`blog` directory][config.blog_dir],
as this leads to undefined behavior.
---
#### <!-- md:setting config.post_url_max_categories -->
<!-- md:version 9.2.0 -->
<!-- md:default `1` -->
Use this setting to set an upper bound for the number of categories included in
post URLs if the `categories` placeholder is part of [`post_url_format`]
[config.post_url_format] and the post defines categories:
``` yaml
plugins:
- blog:
post_url_format: "{categories}/{slug}"
post_url_max_categories: 2
```
If more than one category is given, they are joined with `/` after slugifying.
---
#### <!-- md:setting config.post_slugify -->
<!-- md:version 9.2.0 -->
<!-- md:default [`pymdownx.slugs.slugify`][pymdownx.slugs.slugify] -->
Use this setting to change the function for generating URL-compatible slugs
from post titles. By default, the [`slugify`][pymdownx.slugs.slugify] function
from [Python Markdown Extensions] is used as follows:
``` yaml
plugins:
- blog:
post_slugify: !!python/object/apply:pymdownx.slugs.slugify
kwds:
case: lower
```
The default configuration is Unicode-aware and should produce good slugs for all
languages. Of course, you can also provide a custom slugification function for
more granular control.
[pymdownx.slugs.slugify]: https://github.com/facelessuser/pymdown-extensions/blob/01c91ce79c91304c22b4e3d7a9261accc931d707/pymdownx/slugs.py#L59-L65
[Python Markdown Extensions]: https://facelessuser.github.io/pymdown-extensions/extras/slugs/
---
#### <!-- md:setting config.post_slugify_separator -->
<!-- md:version 9.2.0 -->
<!-- md:default `-` -->
Use this setting to change the separator that is passed to the slugification
function set as part of [`post_slugify`][config.post_slugify]. While the default
is a hyphen, it can be set to any string, e.g., `_`:
``` yaml
plugins:
- blog:
post_slugify_separator: _
```
---
#### <!-- md:setting config.post_excerpt -->
<!-- md:version 9.2.0 -->
<!-- md:default `optional` -->
By default, the plugin makes [post excerpts](../setup/setting-up-a-blog.md#adding-an-excerpt)
optional. When a post doesn't define an excerpt, views include the entire post.
This setting can be used to make post excerpts required:
=== "Optional"
``` yaml
plugins:
- blog:
post_excerpt: optional
```
=== "Required"
``` yaml
plugins:
- blog:
post_excerpt: required
```
When post excerpts are required, posts without excerpt separators raise an
error. Thus, this setting is useful when you want to make sure that all posts
have excerpts defined.
---
#### <!-- md:setting config.post_excerpt_max_authors -->
<!-- md:version 9.2.0 -->
<!-- md:default `1` -->
Use this setting to set an upper bound for the number of authors rendered in
post excerpts. While each post may be written by multiple authors, this setting
allows to limit the display to just a few or even a single author, or disable
authors in post excerpts:
=== "Render up to 2 authors"
``` yaml
plugins:
- blog:
post_excerpt_max_authors: 2
```
=== "Disable authors"
``` yaml
plugins:
- blog:
post_excerpt_max_authors: 0
```
This only applies to post excerpts in views. Posts always render all authors.
---
#### <!-- md:setting config.post_excerpt_max_categories -->
<!-- md:version 9.2.0 -->
<!-- md:default `5` -->
Use this setting to set an upper bound for the number of categories rendered in
post excerpts. While each post may be assigned to multiple categories, this
setting allows to limit the display to just a few or even a single category, or
disable categories in post excerpts:
=== "Render up to 2 categories"
``` yaml
plugins:
- blog:
post_excerpt_max_categories: 2
```
=== "Disable categories"
``` yaml
plugins:
- blog:
post_excerpt_max_categories: 0
```
This only applies to post excerpts in views. Posts always render all categories.
---
#### <!-- md:setting config.post_excerpt_separator -->
<!-- md:version 9.2.0 -->
<!-- md:default <code><!-- more --></code> -->
Use this setting to set the separator the plugin will look for in a post's
content when generating post excerpts. All content __before__ the separator is
considered to be part of the excerpt:
``` yaml
plugins:
- blog:
post_excerpt_separator: <!-- more -->
```
It is common practice to use an HTML comment as a separator.
---
#### <!-- md:setting config.post_readtime -->
<!-- md:version 9.2.0 -->
<!-- md:default `true` -->
Use this setting to control whether the plugin should automatically compute the
reading time of a post, which is then rendered in post excerpts, as well as in
posts themselves:
``` yaml
plugins:
- blog:
post_readtime: false
```
---
#### <!-- md:setting config.post_readtime_words_per_minute -->
<!-- md:version 9.2.0 -->
<!-- md:default `265` -->
Use this setting to change the number of words that a reader is expected to read
per minute when computing the reading time of a post. If you want to fine-tune
it, use:
``` yaml
plugins:
- blog:
post_readtime_words_per_minute: 300
```
A reading time of 265 words per minute is considered to be the
[average reading time of an adult].
[average reading time of an adult]: https://help.medium.com/hc/en-us/articles/214991667-Read-time
### Archive
The following settings are available for archive pages:
---
#### <!-- md:setting config.archive -->
<!-- md:version 9.2.0 -->
<!-- md:default `true` -->
Use this setting to enable or disable archive pages. An archive page shows all
posts for a specific interval (e.g. year, month, etc.) in reverse order. If you
want to disable archive pages, use:
``` yaml
plugins:
- blog:
archive: false
```
---
#### <!-- md:setting config.archive_name -->
<!-- md:version 9.2.0 -->
<!-- md:default computed -->
Use this setting to change the title of the archive section the plugin adds to
the navigation. If this setting is omitted, it's sourced from the translations.
If you want to change it, use:
``` yaml
plugins:
- blog:
archive_name: Archive
```
---
#### <!-- md:setting config.archive_date_format -->
<!-- md:version 9.2.0 -->
<!-- md:default `yyyy` -->
Use this setting to change the date format used for archive page titles. The
format string must adhere to [babel]'s [pattern syntax]. Some popular choices:
=== "2024"
``` yaml
plugins:
- blog:
archive_date_format: yyyy
```
=== "January 2024"
``` yaml
plugins:
- blog:
archive_date_format: MMMM yyyy
```
Note that depending on the [site language], results might look different for
other languages.
---
#### <!-- md:setting config.archive_url_date_format -->
<!-- md:version 9.2.0 -->
<!-- md:default `yyyy` -->
Use this setting to change the date format used for archive page URLs. The
format string must adhere to [babel]'s [pattern syntax] and should not contain
whitespace. Some popular choices:
=== ":material-link: blog/archive/2024/"
``` yaml
plugins:
- blog:
archive_url_date_format: yyyy
```
=== ":material-link: blog/archive/2024/01/"
``` yaml
plugins:
- blog:
archive_url_date_format: yyyy/MM
```
---
#### <!-- md:setting config.archive_url_format -->
<!-- md:version 9.2.0 -->
<!-- md:default `archive/{date}` -->
Use this setting to change the format string that is used when generating
archive page URLs. You can freely combine placeholders, and join them with
slashes or other characters:
=== ":material-link: blog/archive/2024/"
``` yaml
plugins:
- blog:
archive_url_format: "archive/{date}"
```
=== ":material-link: blog/2024/"
``` yaml
plugins:
- blog:
archive_url_format: "{date}"
```
The following placeholders are available:
- `date` – Archive date, formatted with [`archive_url_date_format`][config.archive_url_date_format]
---
#### <!-- md:setting config.archive_pagination -->
<!-- md:sponsors -->
<!-- md:version insiders-4.44.0 -->
<!-- md:default `true` -->
Use this setting to enable or disable pagination for archive pages. The value
of this setting is inherited from [`pagination`][config.pagination], unless it's
explicitly set. To disable pagination, use:
``` yaml
plugins:
- blog:
archive_pagination: false
```
---
#### <!-- md:setting config.archive_pagination_per_page -->
<!-- md:sponsors -->
<!-- md:version insiders-4.44.0 -->
<!-- md:default `10` -->
Use this setting to change the number of posts rendered per archive page. The
value of this setting is inherited from [`pagination_per_page`]
[config.pagination_per_page], unless it's explicitly set. To change it, use:
``` yaml
plugins:
- blog:
archive_pagination_per_page: 5
```
---
#### <!-- md:setting config.archive_toc -->
<!-- md:version 9.2.0 -->
<!-- md:default `false` -->
Use this setting to leverage the table of contents to display post titles on all
archive pages. The value of this setting is inherited from [`blog_toc`]
[config.blog_toc], unless it's explicitly set. To change it, use
``` yaml
plugins:
- blog:
archive_toc: true
```
### Categories
The following settings are available for category pages:
---
#### <!-- md:setting config.categories -->
<!-- md:version 9.2.0 -->
<!-- md:default `true` -->
Use this setting to enable or disable category pages. A category page shows all
posts for a specific category in reverse chronological order. If you want to
disable category pages, use:
``` yaml
plugins:
- blog:
categories: false
```
---
#### <!-- md:setting config.categories_name -->
<!-- md:version 9.2.0 -->
<!-- md:default computed -->
Use this setting to change the title of the category section the plugin adds to
the navigation. If this setting is omitted, it's sourced from the translations.
If you want to change it, use:
``` yaml
plugins:
- blog:
categories_name: Categories
```
---
#### <!-- md:setting config.categories_url_format -->
<!-- md:version 9.2.0 -->
<!-- md:default `category/{slug}` -->
Use this setting to change the format string that is used when generating
category page URLs. You can freely combine placeholders, and join them with
slashes or other characters:
=== ":material-link: blog/category/:material-dots-horizontal:/"
``` yaml
plugins:
- blog:
categories_url_format: "category/{slug}"
```
=== ":material-link: blog/:material-dots-horizontal:/"
``` yaml
plugins:
- blog:
categories_url_format: "{slug}"
```
The following placeholders are available:
- `slug` – Category, slugified with [`categories_slugify`][config.categories_slugify]
---
#### <!-- md:setting config.categories_slugify -->
<!-- md:version 9.2.0 -->
<!-- md:default [`pymdownx.slugs.slugify`][pymdownx.slugs.slugify] -->
Use this setting to change the function for generating URL-compatible slugs
from categories. By default, the [`slugify`][pymdownx.slugs.slugify] function
from [Python Markdown Extensions] is used as follows:
``` yaml
plugins:
- blog:
categories_slugify: !!python/object/apply:pymdownx.slugs.slugify
kwds:
case: lower
```
The default configuration is Unicode-aware and should produce good slugs for all
languages. Of course, you can also provide a custom slugification function for
more granular control.
---
#### <!-- md:setting config.categories_slugify_separator -->
<!-- md:version 9.2.0 -->
<!-- md:default `-` -->
Use this setting to change the separator that is passed to the slugification
function set as part of [`categories_slugify`][config.categories_slugify]. While
the default is a hyphen, it can be set to any string, e.g., `_`:
``` yaml
plugins:
- blog:
categories_slugify_separator: _
```
---
#### <!-- md:setting config.categories_sort_by -->
<!-- md:sponsors -->
<!-- md:version insiders-4.45.0 -->
<!-- md:default `material.plugins.blog.view_name` -->
Use this setting to specify a custom function for sorting categories. For
example, if you want to sort categories by the number of posts they contain,
use the following configuration:
``` yaml
plugins:
- blog:
categories_sort_by: !!python/name:material.plugins.blog.view_post_count
```
Don't forget to enable [`categories_sort_reverse`][config.categories_sort_reverse].
You can define your own comparison function, which must return something
that can be compared while sorting, i.e., a string or number.
---
#### <!-- md:setting config.categories_sort_reverse -->
<!-- md:sponsors -->
<!-- md:version insiders-4.45.0 -->
<!-- md:default `false` -->
Use this setting to reverse the order in which categories are sorted. By
default, categories are sorted in ascending order, but you can reverse ordering
as follows:
``` yaml
plugins:
- blog:
categories_sort_reverse: true
```
---
#### <!-- md:setting config.categories_allowed -->
<!-- md:version 9.2.0 -->
<!-- md:default none -->
The plugin allows to check categories against a predefined list, in order to
catch typos or make sure that categories are not arbitrarily added. Specify the
categories you want to allow with:
``` yaml
plugins:
- blog:
categories_allowed:
- Search
- Performance
```
The plugin stops the build if a post references a category that is not part of
this list. Posts can be assigned to categories by using the [`categories`]
[meta.categories] metadata property.
---
#### <!-- md:setting config.categories_pagination -->
<!-- md:sponsors -->
<!-- md:version insiders-4.44.0 -->
<!-- md:default `true` -->
Use this setting to enable or disable pagination for category pages. The value
of this setting is inherited from [`pagination`][config.pagination], unless it's
explicitly set. To disable pagination, use:
``` yaml
plugins:
- blog:
categories_pagination: false
```
---
#### <!-- md:setting config.categories_pagination_per_page -->
<!-- md:sponsors -->
<!-- md:version insiders-4.44.0 -->
<!-- md:default `10` -->
Use this setting to change the number of posts rendered per category page. The
value of this setting is inherited from [`pagination_per_page`]
[config.pagination_per_page], unless it's explicitly set. To change it, use:
``` yaml
plugins:
- blog:
categories_pagination_per_page: 5
```
---
#### <!-- md:setting config.categories_toc -->
<!-- md:version 9.2.0 -->
<!-- md:default `false` -->
Use this setting to leverage the table of contents to display post titles on all
category pages. The value of this setting is inherited from [`blog_toc`]
[config.blog_toc], unless it's explicitly set. To change it, use:
``` yaml
plugins:
- blog:
categories_toc: true
```
### Authors
The following settings are available for authors:
---
#### <!-- md:setting config.authors -->
<!-- md:version 9.2.0 -->
<!-- md:default `true` -->
Use this setting to enable or disable post authors. If this setting is enabled,
the plugin will look for a file named [`.authors.yml`][config.authors_file] and
render authors in posts and views. Disable this behavior with:
``` yaml
plugins:
- blog:
authors: false
```
---
#### <!-- md:setting config.authors_file -->
<!-- md:version 9.2.0 -->
<!-- md:default `{blog}/.authors.yml` -->
Use this setting to change the path of the file where the author information for
your posts resides. It's normally not necessary to change this setting, but if
you need to, use:
``` yaml
plugins:
- blog:
authors_file: "{blog}/.authors.yml"
```
The following placeholders are available:
- `blog` – [`blog` directory][config.blog_dir]
The provided path is resolved from the [`docs` directory][mkdocs.docs_dir].
!!! info "Format of author information"
The `.authors.yml` file must adhere to the following format:
``` yaml title=".authors.yml"
authors:
<author>:
name: string # Author name
description: string # Author description
avatar: url # Author avatar
slug: url # Author profile slug
url: url # Author website URL
```
Note that `<author>` must be set to an identifier for associating authors
with posts, e.g., a GitHub username like `squidfunk`. This identifier can
then be used in the [`authors`][meta.authors] metadata property of
a post. Multiple authors are supported. As an example, see
[the `.authors.yml` file][.authors.yml] we're using for our blog.
[.authors.yml]: https://github.com/squidfunk/mkdocs-material/blob/master/docs/blog/.authors.yml
---
#### <!-- md:setting config.authors_profiles -->
<!-- md:sponsors -->
<!-- md:version insiders-4.46.0 -->
<!-- md:default `false` -->
Use this setting to enable or disable automatically generated author profiles.
An author profile shows all posts by an author in reverse chronological order.
You can enable author profiles with:
``` yaml
plugins:
- blog:
authors_profiles: true
```
---
#### <!-- md:setting config.authors_profiles_name -->
<!-- md:sponsors -->
<!-- md:version insiders-4.46.0 -->
<!-- md:default computed -->
Use this setting to change the title of the authors section the plugin adds to
the navigation. If this setting is omitted, it's sourced from the translations.
If you want to change it, use:
``` yaml
plugins:
- blog:
authors_profiles_name: Authors
```
---
#### <!-- md:setting config.authors_profiles_url_format -->
<!-- md:sponsors -->
<!-- md:version insiders-4.46.0 -->
<!-- md:default `author/{slug}` -->
Use this setting to change the format string that is used when generating
author profile URLs. You can freely combine placeholders, and join them with
slashes or other characters:
=== ":material-link: blog/author/:material-dots-horizontal:/"
``` yaml
plugins:
- blog:
authors_profiles_url_format: "author/{slug}"
```
=== ":material-link: blog/:material-dots-horizontal:/"
``` yaml
plugins:
- blog:
authors_profiles_url_format: "{slug}"
```
The following placeholders are available:
- `slug` – Author slug or identifier from [`authors_file`][config.authors_file]
- `name` – Author name from [`authors_file`][config.authors_file]
---
#### <!-- md:setting config.authors_profiles_pagination -->
<!-- md:sponsors -->
<!-- md:version insiders-4.46.0 -->
<!-- md:default `true` -->
Use this setting to enable or disable pagination for author profiles. The value
of this setting is inherited from [`pagination`][config.pagination], unless it's
explicitly set. To disable pagination, use:
``` yaml
plugins:
- blog:
authors_profiles_pagination: false
```
---
#### <!-- md:setting config.authors_profiles_pagination_per_page -->
<!-- md:sponsors -->
<!-- md:version insiders-4.46.0 -->
<!-- md:default `10` -->
Use this setting to change the number of posts rendered per archive page. The
value of this setting is inherited from [`pagination_per_page`]
[config.pagination_per_page], unless it's explicitly set. To change it, use:
``` yaml
plugins:
- blog:
authors_profiles_pagination_per_page: 5
```
---
#### <!-- md:setting config.authors_profiles_toc -->
<!-- md:sponsors -->
<!-- md:version insiders-4.46.0 -->
<!-- md:default `false` -->
Use this setting to leverage the table of contents to display post titles on all
author profiles. The value of this setting is inherited from [`blog_toc`]
[config.blog_toc], unless it's explicitly set. To change it, use:
``` yaml
plugins:
- blog:
authors_profiles_toc: true
```
### Pagination
The following settings are available for pagination:
---
#### <!-- md:setting config.pagination -->
<!-- md:version 9.2.0 -->
<!-- md:default `true` -->
Use this setting to enable or disable pagination in views – generated pages
that show posts or subsets of posts in reverse chronological order. If you want
to disable pagination, use:
``` yaml
plugins:
- blog:
pagination: false
```
---
#### <!-- md:setting config.pagination_per_page -->
<!-- md:version 9.2.0 -->
<!-- md:default `10` -->
Use this setting to change the number of posts rendered per page. If you have
rather long post excerpts, it can be a good idea to reduce the number of posts
per page:
``` yaml
plugins:
- blog:
pagination_per_page: 5
```
---
#### <!-- md:setting config.pagination_url_format -->
<!-- md:version 9.2.0 -->
<!-- md:default `page/{page}` -->
Use this setting to change the format string that is used when generating
paginated view URLs. You can freely combine placeholders, and join them with
slashes or other characters:
=== ":material-link: blog/page/n/"
``` yaml
plugins:
- blog:
pagination_url_format: "page/{page}"
```
=== ":material-link: blog/n/"
``` yaml
plugins:
- blog:
pagination_url_format: "{page}"
```
The following placeholders are available:
- `page` – Page number
---
#### <!-- md:setting config.pagination_format -->
<!-- md:version 9.2.0 -->
<!-- md:default `~2~` -->
The plugin uses the [paginate] module to generate the pagination markup using a
special syntax. Use this setting to customize how pagination is constructed.
Some popular choices:
=== "1 2 3 .. n"
``` yaml
plugins:
- blog:
pagination_format: "~2~"
```
=== "1 2 3 .. n :material-chevron-right: :material-chevron-double-right:"
``` yaml
plugins:
- blog:
pagination_format: "$link_first $link_previous ~2~ $link_next $link_last"
```
=== "1 :material-chevron-right:"
``` yaml
plugins:
- blog:
pagination_format: "$link_previous $page $link_next"
```
The following placeholders are supported by [paginate]:
- `#!css $first_page` – Number of first reachable page
- `#!css $last_page` – Number of last reachable page
- `#!css $page` – Number of currently selected page
- `#!css $page_count` – Number of reachable pages
- `#!css $items_per_page` – Maximal number of items per page
- `#!css $first_item` – Index of first item on the current page
- `#!css $last_item` – Index of last item on the current page
- `#!css $item_count` – Total number of items
- `#!css $link_first` – Link to first page (unless on first page)
- `#!css $link_last` – Link to last page (unless on last page)
- `#!css $link_previous` – Link to previous page (unless on first page)
- `#!css $link_next` – Link to next page (unless on last page)
[paginate]: https://pypi.org/project/paginate/
---
#### <!-- md:setting config.pagination_if_single_page -->
<!-- md:version 9.2.0 -->
<!-- md:default `false` -->
Use this setting to control whether pagination should be automatically disabled
when the view only consists of a single page. If you want to always render
pagination, use:
``` yaml
plugins:
- blog:
pagination_if_single_page: true
```
---
#### <!-- md:setting config.pagination_keep_content -->
<!-- md:version 9.2.0 -->
<!-- md:default `false` -->
Use this setting to enable or disable persistence of content, i.e., if paginated
views should also display the content of their containing view. If you want to
enable this behavior, use:
``` yaml
plugins:
- blog:
pagination_keep_content: true
```
### Drafts
The following settings are available for drafts:
---
#### <!-- md:setting config.draft -->
<!-- md:version 9.2.0 -->
<!-- md:default `false` -->
Rendering [draft posts][meta.draft] can be useful in deploy previews. Use this
setting to specify whether the plugin should include posts marked as drafts when
[building your project]:
=== "Render drafts"
``` yaml
plugins:
- blog:
draft: true
```
=== "Don't render drafts"
``` yaml
plugins:
- blog:
draft: false
```
---
#### <!-- md:setting config.draft_on_serve -->
<!-- md:version 9.2.0 -->
<!-- md:default `true` -->
Use this setting to control whether the plugin should include posts marked as
drafts when [previewing your site]. If you don't wish to include draft posts
when previewing, use:
``` yaml
plugins:
- blog:
draft_on_serve: false
```
[previewing your site]: ../creating-your-site.md#previewing-as-you-write
---
#### <!-- md:setting config.draft_if_future_date -->
<!-- md:version 9.2.0 -->
<!-- md:default `false` -->
The plugin can automatically mark posts with future dates as drafts. When the
date is past today, the post is automatically included when
[building your project], unless explicitly marked as draft:
``` yaml
plugins:
- blog:
draft_if_future_date: true
```
## Usage
### Metadata
Posts can define a handful of metadata properties that specify how the plugin
renders them, in which views they are integrated, and how they are linked to
each other. The metadata of each post is validated against a schema to allow for
a quicker discovery of syntax errors.
The following properties are available:
---
#### <!-- md:setting meta.authors -->
<!-- md:version 9.2.0 -->
<!-- md:flag metadata -->
<!-- md:default none -->
Use this property to associate a post with [authors] by providing a list of
identifiers as defined in the [`authors_file`][config.authors_file]. If an
author can't be resolved, the plugin will terminate with an error:
``` yaml
---
authors:
- squidfunk # (1)!
---
# Post title
...
```
1. Authors are linked by using their identifiers. As an example, see
[the `.authors.yml` file][.authors.yml] we're using for our blog.
[authors]: #authors
---
#### <!-- md:setting meta.categories -->
<!-- md:version 9.2.0 -->
<!-- md:flag metadata -->
<!-- md:default none -->
Use this property to associate a post with one or more [categories][category],
making the post a part of the generated category page. Categories are defined
as a list of strings (whitespaces are allowed):
``` yaml
---
categories:
- Search
- Performance
---
# Post title
...
```
If you want to prevent accidental typos assigning categories to posts, you
can set a predefined list of allowed categories in `mkdocs.yml` by using
the [`categories_allowed`][config.categories_allowed] setting.
---
#### <!-- md:setting meta.date -->
<!-- md:version 9.2.0 -->
<!-- md:flag metadata -->
<!-- md:flag required -->
Use this property to specify a post's date. Note that this property is required,
which means the build fails when it's not set. Additional dates can be set by
using a slightly different syntax:
=== "Date"
``` yaml
---
date: 2024-01-31
---
# Post title
...
```
=== "Update date"
``` yaml
---
date:
created: 2024-01-31 # (1)!
updated: 2024-02-01
---
# Post title
...
```
1. Each post must have a creation date set.
=== "Custom date"
``` yaml
---
date:
created: 2024-01-31
my_custom_date: 2024-02-01 # (1)!
---
# Post title
...
```
1. The blog plugin validates all dates and allows to format them with
[babel]'s [pattern syntax] in templates. When using theme extension,
authors can add custom dates to templates.
This was first requested in #5733.
The following date formats are supported:
- `2024-01-31`
- `2024-01-31T12:00:00`
---
#### <!-- md:setting meta.draft -->
<!-- md:version 9.2.0 -->
<!-- md:flag metadata -->
<!-- md:default none -->
Use this property to mark a post as draft. The plugin allows to include or
exclude posts marked as drafts when [building your project] using the
[`draft`][config.draft] setting. Mark a post as draft with:
``` yaml
---
draft: true
---
# Post title
...
```
---
#### <!-- md:setting meta.pin -->
<!-- md:sponsors -->
<!-- md:version insiders-4.53.0 -->
<!-- md:flag metadata -->
<!-- md:default `false` -->
<!-- md:flag experimental -->
Use this property to pin a post to the top of a view. In case multiple posts are
pinned, the pinned posts are sorted by descending order and appear before all
other posts. Pin a post with:
``` yaml
---
pin: true
---
# Post title
...
```
---
#### <!-- md:setting meta.links -->
<!-- md:sponsors -->
<!-- md:version insiders-4.23.0 -->
<!-- md:flag metadata -->
<!-- md:default none -->
<!-- md:flag experimental -->
Use this property to define a list of links that are rendered in the sidebar of
a post. The property follows the same syntax as [`nav`][mkdocs.nav] in
`mkdocs.yml`, supporting sections and even anchors:
=== "Links"
``` yaml
---
links:
- setup/setting-up-site-search.md
- insiders/index.md
---
# Post title
...
```
=== "Links with sections"
``` yaml
---
links:
- setup/setting-up-site-search.md
- Insiders:
- insiders/index.md
- insiders/getting-started.md
---
# Post title
...
```
=== "Links with anchors"
``` yaml
---
links:
- plugins/search.md # (1)!
- Insiders:
- insiders/how-to-sponsor.md
- insiders/getting-started.md#requirements
---
# Post title
...
```
1. If a link defines an anchor, the plugin resolves the anchor from the
linked page and sets the anchor title as a [subtitle].
All relative links are resolved from the [`docs` directory][mkdocs.docs_dir].
[subtitle]: ../reference/index.md#setting-the-page-subtitle
---
#### <!-- md:setting meta.readtime -->
<!-- md:version 9.2.0 -->
<!-- md:flag metadata -->
<!-- md:default computed -->
Use this property to explicitly set the reading time of a post in minutes. When
[`post_readtime`][config.post_readtime] is enabled, the plugin computes the
reading time of a post, which can be overridden with:
``` yaml
---
readtime: 15
---
# Post title
...
```
---
#### <!-- md:setting meta.slug -->
<!-- md:version 9.2.0 -->
<!-- md:flag metadata -->
<!-- md:default computed -->
Use this property to explicitly set the slug of a post. By default, the slug of
a post is automatically computed by the [`post_slugify`][config.post_slugify]
function from the post's title, which can be overridden with:
``` yaml
---
slug: help-im-trapped-in-a-universe-factory
---
# Post title
...
```
Slugs are passed to [`post_url_format`][config.post_url_format].
---
!!! question "Missing something?"
When setting up your blog or migrating from another blog framework, you
might discover that you're missing specific functionality – we're happy to
consider adding it to the plugin! You can [open a discussion] to
ask a question, or create a [change request] on our [issue tracker], so we
can find out if it might be a good fit for the plugin.
[open a discussion]: https://github.com/squidfunk/mkdocs-material/discussions
[change request]: ../contributing/requesting-a-change.md
[issue tracker]: https://github.com/squidfunk/mkdocs-material/issues
|