Skip to content
Open
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
1 change: 1 addition & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default defineConfig({
},

lastUpdated: true,
created: true,
cleanUrls: true,
metaChunk: true,

Expand Down
1 change: 1 addition & 0 deletions docs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function sidebarReference(): DefaultTheme.SidebarItem[] {
{ text: 'Prev / Next Links', link: 'prev-next-links' },
{ text: 'Edit Link', link: 'edit-link' },
{ text: 'Last Updated Timestamp', link: 'last-updated' },
{ text: 'Created Timestamp', link: 'created' },
{ text: 'Search', link: 'search' },
{ text: 'Carbon Ads', link: 'carbon-ads' }
]
Expand Down
40 changes: 40 additions & 0 deletions docs/en/reference/default-theme-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,46 @@ export interface LastUpdatedOptions {
}
```

## created

- Type: `CreatedOptions`

Allows customization for the created text and date format.

```ts
export default {
themeConfig: {
created: {
text: 'Created at',
formatOptions: {
dateStyle: 'full',
timeStyle: 'medium'
}
}
}
}
```

```ts
export interface CreatedOptions {
/**
* Set custom created text.
*
* @default 'Created'
*/
text?: string

/**
* Set options for created time formatting.
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#using_options
*
* @default
* { dateStyle: 'short', timeStyle: 'short' }
*/
formatOptions?: Intl.DateTimeFormatOptions & { forceLocale?: boolean }
}
```

## algolia

- Type: `AlgoliaSearch`
Expand Down
29 changes: 29 additions & 0 deletions docs/en/reference/default-theme-created.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Created

The created time of the content will be displayed in the lower right corner of the page. To enable it, add `created` options to your config.

::: info
VitePress displays the "created" time using the timestamp of the first Git commit for each file. To enable this, the Markdown file must be committed to Git.

Internally, VitePress runs `git log -1 --pretty=%at --follow --diff-filter=A` on each file to retrieve its timestamp. If all pages show the same created time, please refer to the same paragraph on the [Last Updated](./default-theme-last-updated) page.
:::

## Site-Level Config

```js
export default {
created: true
}
```

## Frontmatter Config

This can be disabled per-page using the `created` option on frontmatter:

```yaml
---
created: false
---
```

Also refer [Default Theme: Created](./default-theme-config#created) for more details. Any truthy value at theme-level will also enable the feature unless explicitly disabled at site or page level.
13 changes: 13 additions & 0 deletions docs/en/reference/frontmatter-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ lastUpdated: false
---
```

### created

- Type: `boolean | Date`
- Default: `true`

Whether to display [created](./default-theme-created) text in the footer of the current page. If a datetime is specified, it will be displayed instead of the first git commit timestamp.

```yaml
---
created: false
---
```

### editLink

- Type: `boolean`
Expand Down
1 change: 1 addition & 0 deletions docs/en/reference/runtime-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface PageData {
params?: Record<string, any>
isNotFound?: boolean
lastUpdated?: number
created?: number
}
```

Expand Down
9 changes: 9 additions & 0 deletions docs/en/reference/site-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,15 @@ Whether to get the last updated timestamp for each page using Git. The timestamp

When using the default theme, enabling this option will display each page's last updated time. You can customize the text via [`themeConfig.lastUpdatedText`](./default-theme-config#lastupdatedtext) option.

### created

- Type: `boolean`
- Default: `false`

Whether to get the created timestamp for each page using Git. The timestamp will be included in each page's page data, accessible via [`useData`](./runtime-api#usedata).

When using the default theme, enabling this option will display each page's created time. You can customize the text via [`themeConfig.created.text`](./default-theme-config#created) option.

## Customization

### markdown
Expand Down
5 changes: 5 additions & 0 deletions docs/zh/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export default defineAdditionalConfig({
text: '最后更新于'
},

created: {
text: '创建于'
},

notFound: {
title: '页面未找到',
quote:
Expand Down Expand Up @@ -160,6 +164,7 @@ function sidebarReference(): DefaultTheme.SidebarItem[] {
{ text: '上下页链接', link: 'prev-next-links' },
{ text: '编辑链接', link: 'edit-link' },
{ text: '最后更新时间戳', link: 'last-updated' },
{ text: '创建时间戳', link: 'created' },
{ text: '搜索', link: 'search' },
{ text: 'Carbon Ads', link: 'carbon-ads' }
]
Expand Down
40 changes: 40 additions & 0 deletions docs/zh/reference/default-theme-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,46 @@ export interface LastUpdatedOptions {
}
```

## created

- 类型:`CreatedOptions`

允许自定义文档创建的文本和日期格式。

```ts
export default {
themeConfig: {
created: {
text: 'Created at',
formatOptions: {
dateStyle: 'full',
timeStyle: 'medium'
}
}
}
}
```

```ts
export interface CreatedOptions {
/**
* Set custom created text.
*
* @default 'Created'
*/
text?: string

/**
* Set options for created time formatting.
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#using_options
*
* @default
* { dateStyle: 'short', timeStyle: 'short' }
*/
formatOptions?: Intl.DateTimeFormatOptions & { forceLocale?: boolean }
}
```

## algolia

- 类型:`AlgoliaSearch`
Expand Down
29 changes: 29 additions & 0 deletions docs/zh/reference/default-theme-created.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 创建于 {#created}

文档的创建时间会显示在页面右下角。要启用它,请将 `created` 选项添加到配置中。

::: tip
VitePress 通过每个文件第一次 Git 提交的时间戳显示"创建"时间,因此你必须提交 markdown 文件才能看到创建时间。

具体实现上,VitePress 会对每个文件执行`git log -1 --pretty=%at --follow --diff-filter=A`命令以获取时间戳。若所有页面显示相同的创建时间,请参考[最后更新时间](./default-theme-last-updated)页面中的相同段落。
:::

## 全局配置 {#site-level-config}

```js
export default {
created: true
}
```

## frontmatter 配置 {#frontmatter-config}

可以使用 frontmatter 上的 `created` 选项单独禁用某个页面的最后更新展示:

```yaml
---
created: false
---
```

另请参阅[默认主题:创建时间](./default-theme-config#created) 了解更多详细信息。主题级别的任何 [truthy](https://developer.mozilla.org/zh-CN/docs/Glossary/Truthy) 值也将启用该功能,除非在站点或页面级别明确禁用。
13 changes: 13 additions & 0 deletions docs/zh/reference/frontmatter-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ lastUpdated: false
---
```

### created

- 类型:`boolean | Date`
- 默认值:`true`

是否在当前页面的页脚中显示[创建时间](./default-theme-created)的文本。如果指定了日期时间,则会显示该日期时间而不是初次 git 提交的时间戳。

```yaml
---
created: false
---
```

### editLink

- 类型:`boolean`
Expand Down
1 change: 1 addition & 0 deletions docs/zh/reference/runtime-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ interface PageData {
params?: Record<string, any>
isNotFound?: boolean
lastUpdated?: number
created?: number
}
```

Expand Down
9 changes: 9 additions & 0 deletions docs/zh/reference/site-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,15 @@ export default {

使用默认主题时,启用此选项将显示每个页面的最后更新时间。可以通过 [`themeConfig.lastUpdatedText`](./default-theme-config#lastupdatedtext) 选项自定义文本。

### created

- 类型:`boolean`
- 默认值: `false`

是否使用 Git 获取每个页面的文档创建时间戳。时间戳将包含在每个页面的页面数据中,可通过 [`useData`](./runtime-api#usedata) 访问。

使用默认主题时,启用此选项将显示每个页面的文档创建时间。可以通过 [`themeConfig.created.text`](./default-theme-config#created) 选项自定义文本。

## 自定义 {#customization}

### markdown
Expand Down
19 changes: 14 additions & 5 deletions src/client/theme-default/components/VPDocFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useData } from '../composables/data'
import { useEditLink } from '../composables/edit-link'
import { usePrevNext } from '../composables/prev-next'
import VPLink from './VPLink.vue'
import VPDocFooterLastUpdated from './VPDocFooterLastUpdated.vue'
import VPDocFooterTimestamp from './VPDocFooterTimestamp.vue'

const { theme, page, frontmatter } = useData()

Expand All @@ -15,10 +15,12 @@ const hasEditLink = computed(
() => theme.value.editLink && frontmatter.value.editLink !== false
)
const hasLastUpdated = computed(() => page.value.lastUpdated)
const hasCreated = computed(() => page.value.created)
const showFooter = computed(
() =>
hasEditLink.value ||
hasLastUpdated.value ||
hasCreated.value ||
control.value.prev ||
control.value.next
)
Expand All @@ -28,17 +30,20 @@ const showFooter = computed(
<footer v-if="showFooter" class="VPDocFooter">
<slot name="doc-footer-before" />

<div v-if="hasEditLink || hasLastUpdated" class="edit-info">
<div v-if="hasEditLink || hasLastUpdated || hasCreated" class="edit-info">
<div v-if="hasEditLink" class="edit-link">
<VPLink class="edit-link-button" :href="editLink.url" :no-icon="true">
<span class="vpi-square-pen edit-link-icon" />
{{ editLink.text }}
</VPLink>
</div>

<div v-if="hasLastUpdated" class="last-updated">
<VPDocFooterLastUpdated />
</div>
<table v-if="hasLastUpdated || hasCreated" class="VPTimestamps">
<tbody>
<VPDocFooterTimestamp :is-created="true" v-if="hasCreated" />
<VPDocFooterTimestamp :is-created="false" v-if="hasLastUpdated" />
</tbody>
</table>
</div>

<nav
Expand Down Expand Up @@ -96,6 +101,10 @@ const showFooter = computed(
}
}

.edit-link {
align-self: flex-end;
}

.edit-link-button {
display: flex;
align-items: center;
Expand Down
Loading