Skip to content
This repository has been archived by the owner on Apr 5, 2019. It is now read-only.

Commit

Permalink
add default index file
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Apr 27, 2018
1 parent 08d2078 commit f390ff3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
3 changes: 0 additions & 3 deletions lib/engine/default-theme/layouts/index.vue
Expand Up @@ -3,9 +3,6 @@
<div class="container">
<h1 class="title">{{ $siteData.title }}</h1>
<h2 class="description">{{ $siteData.description }}</h2>
<div>
<router-link to="/zh-cn">中文</router-link>
</div>
<div class="post-list">
<div class="post" v-for="post in page.posts" :key="post.slug">
<router-link class="post-title" :to="post.permalink">{{ post.attributes.title || post.slug }}</router-link>
Expand Down
26 changes: 21 additions & 5 deletions lib/index.js
Expand Up @@ -188,9 +188,23 @@ class Peco {

await this.onInitFiles(
new Map(
fileStats.map(stats => {
return [stats.path, { stats }]
})
[
// Add a default index.md file
['index.md', {
isVirtual: true,
data: {
attributes: {
layout: 'index',
type: 'index'
},
permalink: '/',
slug: ''
}
}],
...fileStats.map(stats => {
return [stats.path, { stats }]
})
]
)
)

Expand Down Expand Up @@ -438,10 +452,12 @@ class Peco {
await Promise.all(
files.map(async ([filepath, file]) => {
// eslint-disable-next-line no-multi-assign
const data = (this.files.get(filepath).data = await this.getFileData(
const data = file.isVirtual ? file.data : await this.getFileData(
filepath,
file.stats
))
)

this.files.get(filepath).data = data

// Write data for index type later
if (data.attributes.type === 'index') {
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/normalize-config.js
Expand Up @@ -25,7 +25,8 @@ async function normalizeConfig(config = {}, baseDir) {
permalink: config.permalink || ':year/:month/:day/:slug',
markdown: config.markdown || {},
defaultLocale: config.defaultLocale || 'en',
localeNames: config.locales && Object.keys(config.locales)
localeNames: config.locales && Object.keys(config.locales),
pagination: config.pagination || { perPage: 30 }
})
}
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/write-index.js
Expand Up @@ -63,7 +63,8 @@ module.exports = api => {
}

const pagination = Object.assign(
{ perPage: 30 },
{},
api.config.pagination,
data.attributes.pagination
)

Expand Down

0 comments on commit f390ff3

Please sign in to comment.