Skip to content

Commit 0903027

Browse files
jcbhmrbrc-dd
andauthored
feat(theme): auto style markdown content in home page (#3561)
BREAKING CHANGES: styles are now applied by default to markdown content when `layout: home` is set in frontmatter. If they conflict with the styles of your custom component, please set `markdownStyles: false` in frontmatter. --------- Co-authored-by: Divyansh Singh <[email protected]>
1 parent c70b6bf commit 0903027

File tree

7 files changed

+129
-14
lines changed

7 files changed

+129
-14
lines changed

Diff for: docs/reference/default-theme-home-page.md

+27
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,30 @@ type FeatureIcon =
166166
height: string
167167
}
168168
```
169+
170+
## Markdown Content
171+
172+
You can add additional content to your site's homepage just by adding Markdown below the `---` frontmatter divider.
173+
174+
````md
175+
---
176+
layout: home
177+
178+
hero:
179+
name: VitePress
180+
text: Vite & Vue powered static site generator.
181+
---
182+
183+
## Getting Started
184+
185+
You can get started using VitePress right away using `npx`!
186+
187+
```sh
188+
npm init
189+
npx vitepress init
190+
```
191+
````
192+
193+
::: info
194+
VitePress didn't always auto-style the extra content of the `layout: home` page. To revert to older behavior, you can add `markdownStyles: false` to the frontmatter.
195+
:::

Diff for: src/client/theme-default/components/VPHome.vue

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<script setup lang="ts">
22
import VPHomeHero from './VPHomeHero.vue'
33
import VPHomeFeatures from './VPHomeFeatures.vue'
4+
import VPHomeContent from './VPHomeContent.vue'
5+
import { useData } from '../composables/data'
6+
7+
const { frontmatter } = useData()
48
</script>
59

610
<template>
@@ -19,23 +23,21 @@ import VPHomeFeatures from './VPHomeFeatures.vue'
1923
<VPHomeFeatures />
2024
<slot name="home-features-after" />
2125

22-
<Content />
26+
<VPHomeContent v-if="frontmatter.markdownStyles !== false">
27+
<Content />
28+
</VPHomeContent>
29+
<Content v-else />
2330
</div>
2431
</template>
2532

2633
<style scoped>
2734
.VPHome {
28-
padding-bottom: 96px;
29-
}
30-
31-
.VPHome :deep(.VPHomeSponsors) {
32-
margin-top: 112px;
33-
margin-bottom: -128px;
35+
margin-bottom: 96px;
3436
}
3537
3638
@media (min-width: 768px) {
3739
.VPHome {
38-
padding-bottom: 128px;
40+
margin-bottom: 128px;
3941
}
4042
}
4143
</style>
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<script setup lang="ts">
2+
import { useWindowSize } from '@vueuse/core'
3+
4+
const { width: vw } = useWindowSize({ includeScrollbar: false })
5+
</script>
6+
7+
<template>
8+
<div
9+
class="vp-doc container"
10+
:style="vw ? { '--vp-offset': `calc(50% - ${vw / 2}px)` } : {}"
11+
>
12+
<slot />
13+
</div>
14+
</template>
15+
16+
<style scoped>
17+
.container {
18+
margin: auto;
19+
width: 100%;
20+
max-width: 1280px;
21+
padding: 0 24px;
22+
}
23+
24+
@media (min-width: 640px) {
25+
.container {
26+
padding: 0 48px;
27+
}
28+
}
29+
30+
@media (min-width: 960px) {
31+
.container {
32+
width: 100%;
33+
padding: 0 64px;
34+
}
35+
}
36+
37+
.vp-doc :deep(.VPHomeSponsors),
38+
.vp-doc :deep(.VPTeamPage) {
39+
margin-left: var(--vp-offset, calc(50% - 50vw));
40+
margin-right: var(--vp-offset, calc(50% - 50vw));
41+
}
42+
43+
.vp-doc :deep(.VPHomeSponsors h2) {
44+
border-top: none;
45+
letter-spacing: normal;
46+
}
47+
48+
.vp-doc :deep(.VPHomeSponsors a),
49+
.vp-doc :deep(.VPTeamPage a){
50+
text-decoration: none;
51+
}
52+
</style>

Diff for: src/client/theme-default/components/VPHomeSponsors.vue

+27-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,33 @@ withDefaults(defineProps<Props>(), {
4949
<style scoped>
5050
.VPHomeSponsors {
5151
border-top: 1px solid var(--vp-c-gutter);
52-
padding: 88px 24px 96px;
53-
background-color: var(--vp-c-bg);
52+
padding-top: 88px !important;
53+
}
54+
55+
.VPHomeSponsors {
56+
margin: 96px 0;
57+
}
58+
59+
@media (min-width: 768px) {
60+
.VPHomeSponsors {
61+
margin: 128px 0;
62+
}
63+
}
64+
65+
.VPHomeSponsors {
66+
padding: 0 24px;
67+
}
68+
69+
@media (min-width: 768px) {
70+
.VPHomeSponsors {
71+
padding: 0 48px;
72+
}
73+
}
74+
75+
@media (min-width: 960px) {
76+
.VPHomeSponsors {
77+
padding: 0 64px;
78+
}
5479
}
5580
5681
.container {

Diff for: src/client/theme-default/components/VPTeamPage.vue

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66

77
<style scoped>
88
.VPTeamPage {
9-
padding-bottom: 96px;
9+
margin: 96px 0;
1010
}
1111
1212
@media (min-width: 768px) {
1313
.VPTeamPage {
14-
padding-bottom: 128px;
14+
margin: 128px 0;
1515
}
1616
}
1717
18+
.VPHome :slotted(.VPTeamPageTitle) {
19+
border-top: 1px solid var(--vp-c-gutter);
20+
padding-top: 88px !important;
21+
}
22+
1823
:slotted(.VPTeamPageSection + .VPTeamPageSection),
1924
:slotted(.VPTeamMembers + .VPTeamPageSection) {
2025
margin-top: 64px;

Diff for: src/client/theme-default/styles/components/vp-doc.css

+4
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,10 @@
540540
max-width: calc((100% - 24px) / 2) !important;
541541
}
542542

543+
/**
544+
* External links
545+
* -------------------------------------------------------------------------- */
546+
543547
/* prettier-ignore */
544548
:is(.vp-external-link-icon, .vp-doc a[href*='://'], .vp-doc a[target='_blank']):not(.no-icon)::after {
545549
display: inline-block;

Diff for: src/client/theme-default/styles/components/vp-sponsor.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
}
1717

1818
.vp-sponsor-tier {
19-
margin-bottom: 4px;
19+
margin: 0 0 4px !important;
2020
text-align: center;
21-
letter-spacing: 1px;
21+
letter-spacing: 1px !important;
2222
line-height: 24px;
2323
width: 100%;
2424
font-weight: 600;

0 commit comments

Comments
 (0)