@@ -6,19 +6,29 @@ template: overrides/main.html
6
6
7
7
Social cards, also known as social previews, are images that are displayed when
8
8
a link to your project documentation is shared on social media. Material for
9
- MkDocs can generate beautiful social cards automatically, using the colors,
10
- fonts and logo defined in ` mkdocs.yml ` .
9
+ MkDocs can generate beautiful social cards automatically, using the [ colors] [ 1 ] ,
10
+ [ fonts] [ 2 ] and [ logo] [ 3 ] [ ^ 1 ] defined in ` mkdocs.yml ` .
11
+
12
+ [ ^ 1 ] :
13
+ Both types of logos, images (` theme.logo ` ) and icons (` theme.icon.logo ` )
14
+ are supported. While an image logo is used as-is, icons are filled with the
15
+ color used in the header (white or black), which depends on the primary
16
+ color.
17
+
18
+ [ 1 ] : changing-the-colors.md#primary-color
19
+ [ 2 ] : changing-the-fonts.md#regular-font
20
+ [ 3 ] : changing-the-logo-and-icons.md#logo
11
21
12
22
## Configuration
13
23
14
24
### Built-in social cards
15
25
16
- [ :octicons-file-code-24: Source] [ 1 ] ·
17
- [ :octicons-cpu-24: Plugin] [ 1 ] ·
26
+ [ :octicons-file-code-24: Source] [ 4 ] ·
27
+ [ :octicons-cpu-24: Plugin] [ 4 ] ·
18
28
:octicons-beaker-24: Experimental ·
19
- [ :octicons-heart-fill-24:{ .mdx-heart } Insiders only] [ 1 ] { .mdx-insiders }
29
+ [ :octicons-heart-fill-24:{ .mdx-heart } Insiders only] [ 4 ] { .mdx-insiders }
20
30
21
- The [ built-in social cards plugin] [ 1 ] generates a social card image for every
31
+ The [ built-in social cards plugin] [ 4 ] generates a social card image for every
22
32
page and adds the necessary meta tags, so it's displayed on social media when
23
33
shared. Enable it via ` mkdocs.yml ` :
24
34
@@ -27,16 +37,16 @@ plugins:
27
37
- social
28
38
` ` `
29
39
30
- For example, the page on [setting up site analytics][2 ] renders as:
40
+ For example, the page on [setting up site analytics][5 ] renders as:
31
41
32
42
<figure markdown="1">
33
43
34
- [![Social Cards][3 ]][3 ]
44
+ [![Social Cards][6 ]][6 ]
35
45
36
46
<figcaption markdown="1">
37
47
38
48
Want to try it out? Copy the current URL and enter it into [Twitter's Card
39
- validator][4 ] to see how social cards look in action.
49
+ validator][7 ] to see how social cards look in action.
40
50
41
51
</figcaption>
42
52
</figure>
@@ -57,7 +67,59 @@ are available:
57
67
cards_directory: assets/images/social
58
68
` ` `
59
69
60
- [1] : ../insiders/index.md
61
- [2] : setting-up-site-analytics.md
62
- [3] : ../assets/screenshots/social-cards.png
63
- [4] : https://cards-dev.twitter.com/validator
70
+ [4] : ../insiders/index.md
71
+ [5] : setting-up-site-analytics.md
72
+ [6] : ../assets/screenshots/social-cards.png
73
+ [7] : https://cards-dev.twitter.com/validator
74
+
75
+ # ### Caching
76
+
77
+ When enabled, the [social cards plugin][8] automatically fetches the fonts you
78
+ define in `mkdocs.yml` from Google Fonts, and uses them to render the text that
79
+ is displayed on the social card. The font files and generated cards are both
80
+ written to the `.cache` directory, which is used in subsequent builds to detect
81
+ whether the social cards need to be regenerated. You might want to :
82
+
83
+ 1. Ignore the `.cache` directory in your project, by adding it to `.gitignore`.
84
+ 2. When building your site for publishing, use a build cache to save the
85
+ ` .cache` directory in between builds. Taking the example from the
86
+ [publishing guide][9], add the following lines :
87
+
88
+ ` ` ` yaml hl_lines="15-18"
89
+ name: ci
90
+ on:
91
+ push:
92
+ branches:
93
+ - master
94
+ - main
95
+ jobs:
96
+ deploy:
97
+ runs-on: ubuntu-latest
98
+ steps:
99
+ - uses: actions/checkout@v2
100
+ - uses: actions/setup-python@v2
101
+ with:
102
+ python-version: 3.x
103
+ - uses: actions/cache@v2
104
+ with:
105
+ key: ${{ github.ref }}
106
+ path: .cache
107
+ - run: pip install mkdocs-material
108
+ - run: mkdocs gh-deploy --force
109
+ ` ` `
110
+
111
+ [8] : # built-in-social-cards
112
+ [9] : ../publishing-your-site.md
113
+
114
+ # # Usage
115
+
116
+ If you want to adjust the title or set a custom description for the social card,
117
+ you can use the [Metadata][10] extension, which takes precedence over the
118
+ default values.
119
+
120
+ - [Changing the title][11]
121
+ - [Changing the description][12]
122
+
123
+ [10] : ../reference/meta-tags.md#metadata
124
+ [11] : ../reference/meta-tags.md#setting-the-page-title
125
+ [12] : ../reference/meta-tags.md#setting-the-page-description
0 commit comments