Skip to content

Commit

Permalink
feat(theme): auto style markdown content in home page (#3561)
Browse files Browse the repository at this point in the history
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 <40380293+brc-dd@users.noreply.github.com>
  • Loading branch information
jcbhmr and brc-dd authored Feb 17, 2024
1 parent c70b6bf commit 0903027
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 14 deletions.
27 changes: 27 additions & 0 deletions docs/reference/default-theme-home-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,30 @@ type FeatureIcon =
height: string
}
```
## Markdown Content
You can add additional content to your site's homepage just by adding Markdown below the `---` frontmatter divider.
````md
---
layout: home
hero:
name: VitePress
text: Vite & Vue powered static site generator.
---
## Getting Started
You can get started using VitePress right away using `npx`!
```sh
npm init
npx vitepress init
```
````
::: info
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.
:::
18 changes: 10 additions & 8 deletions src/client/theme-default/components/VPHome.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<script setup lang="ts">
import VPHomeHero from './VPHomeHero.vue'
import VPHomeFeatures from './VPHomeFeatures.vue'
import VPHomeContent from './VPHomeContent.vue'
import { useData } from '../composables/data'
const { frontmatter } = useData()
</script>

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

<Content />
<VPHomeContent v-if="frontmatter.markdownStyles !== false">
<Content />
</VPHomeContent>
<Content v-else />
</div>
</template>

<style scoped>
.VPHome {
padding-bottom: 96px;
}
.VPHome :deep(.VPHomeSponsors) {
margin-top: 112px;
margin-bottom: -128px;
margin-bottom: 96px;
}
@media (min-width: 768px) {
.VPHome {
padding-bottom: 128px;
margin-bottom: 128px;
}
}
</style>
52 changes: 52 additions & 0 deletions src/client/theme-default/components/VPHomeContent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<script setup lang="ts">
import { useWindowSize } from '@vueuse/core'
const { width: vw } = useWindowSize({ includeScrollbar: false })
</script>

<template>
<div
class="vp-doc container"
:style="vw ? { '--vp-offset': `calc(50% - ${vw / 2}px)` } : {}"
>
<slot />
</div>
</template>

<style scoped>
.container {
margin: auto;
width: 100%;
max-width: 1280px;
padding: 0 24px;
}
@media (min-width: 640px) {
.container {
padding: 0 48px;
}
}
@media (min-width: 960px) {
.container {
width: 100%;
padding: 0 64px;
}
}
.vp-doc :deep(.VPHomeSponsors),
.vp-doc :deep(.VPTeamPage) {
margin-left: var(--vp-offset, calc(50% - 50vw));
margin-right: var(--vp-offset, calc(50% - 50vw));
}
.vp-doc :deep(.VPHomeSponsors h2) {
border-top: none;
letter-spacing: normal;
}
.vp-doc :deep(.VPHomeSponsors a),
.vp-doc :deep(.VPTeamPage a){
text-decoration: none;
}
</style>
29 changes: 27 additions & 2 deletions src/client/theme-default/components/VPHomeSponsors.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,33 @@ withDefaults(defineProps<Props>(), {
<style scoped>
.VPHomeSponsors {
border-top: 1px solid var(--vp-c-gutter);
padding: 88px 24px 96px;
background-color: var(--vp-c-bg);
padding-top: 88px !important;
}
.VPHomeSponsors {
margin: 96px 0;
}
@media (min-width: 768px) {
.VPHomeSponsors {
margin: 128px 0;
}
}
.VPHomeSponsors {
padding: 0 24px;
}
@media (min-width: 768px) {
.VPHomeSponsors {
padding: 0 48px;
}
}
@media (min-width: 960px) {
.VPHomeSponsors {
padding: 0 64px;
}
}
.container {
Expand Down
9 changes: 7 additions & 2 deletions src/client/theme-default/components/VPTeamPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@

<style scoped>
.VPTeamPage {
padding-bottom: 96px;
margin: 96px 0;
}
@media (min-width: 768px) {
.VPTeamPage {
padding-bottom: 128px;
margin: 128px 0;
}
}
.VPHome :slotted(.VPTeamPageTitle) {
border-top: 1px solid var(--vp-c-gutter);
padding-top: 88px !important;
}
:slotted(.VPTeamPageSection + .VPTeamPageSection),
:slotted(.VPTeamMembers + .VPTeamPageSection) {
margin-top: 64px;
Expand Down
4 changes: 4 additions & 0 deletions src/client/theme-default/styles/components/vp-doc.css
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@
max-width: calc((100% - 24px) / 2) !important;
}

/**
* External links
* -------------------------------------------------------------------------- */

/* prettier-ignore */
:is(.vp-external-link-icon, .vp-doc a[href*='://'], .vp-doc a[target='_blank']):not(.no-icon)::after {
display: inline-block;
Expand Down
4 changes: 2 additions & 2 deletions src/client/theme-default/styles/components/vp-sponsor.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
}

.vp-sponsor-tier {
margin-bottom: 4px;
margin: 0 0 4px !important;
text-align: center;
letter-spacing: 1px;
letter-spacing: 1px !important;
line-height: 24px;
width: 100%;
font-weight: 600;
Expand Down

0 comments on commit 0903027

Please sign in to comment.