This repository has been archived by the owner on Feb 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
185 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const { Nuxt, Builder } = require('nuxt') | ||
const test = require('ava') | ||
const { resolve } = require('path') | ||
|
||
const host = 'localhost' | ||
const port = 3000 | ||
const url = (route) => `http://${host}:${port}/${route}` | ||
|
||
const basicConfig = require(resolve(__dirname, 'fixtures/nuxt.config.js'))({ | ||
content: [ | ||
['posts', { | ||
permalink: ":year/:slug", | ||
routes: [ | ||
{ | ||
path: "/_post", | ||
method: "get" | ||
}, | ||
{ | ||
path: "/archives", | ||
method: "getAll" | ||
} | ||
] | ||
}], | ||
['projects', { | ||
permalink: "/:slug", | ||
isPost: false, | ||
routes: [ | ||
{ | ||
path: "/projects/_slug", | ||
method: "get" | ||
}, | ||
{ | ||
path: "/projects", | ||
method: "getAll" | ||
} | ||
] | ||
}] | ||
] | ||
}) | ||
|
||
let nuxt = null | ||
let server = null | ||
|
||
test.before('Init Nuxt and Nuxtent', async () => { | ||
const config = Object.assign({}, { | ||
rootDir: resolve(__dirname, 'fixtures'), | ||
srcDir: resolve(__dirname, 'fixtures/multiple-content-types'), | ||
dev: false | ||
}, basicConfig) | ||
nuxt = new Nuxt(config) | ||
// await new Builder(nuxt).build() | ||
await nuxt.listen(port, host) | ||
}) | ||
|
||
test('posts content - get', async t => { | ||
const { html } = await nuxt.renderRoute('2016/first-post') | ||
t.true(html.includes('<h1>My First Post</h1><div><p>This is my first post!</p>')) | ||
}) | ||
|
||
// test('content - getAll', async t => { | ||
// const { html } = await nuxt.renderRoute('archives') | ||
// t.true(html.includes('<li><a href="/2016/first-post">My First Post</a></li><li><a href="/2017/second-post">My Second Post</a></li>' | ||
// )) | ||
// }) | ||
|
||
test.after('Closing server', t => { | ||
nuxt.close() | ||
}) |
5 changes: 5 additions & 0 deletions
5
tests/fixtures/multiple-content-types/content/posts/2016-01-10-FirstPost.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: My First Post | ||
--- | ||
|
||
This is my first post! |
5 changes: 5 additions & 0 deletions
5
tests/fixtures/multiple-content-types/content/projects/Ency.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
name: Ency.js | ||
--- | ||
|
||
Pretty cool plugin! |
5 changes: 5 additions & 0 deletions
5
tests/fixtures/multiple-content-types/content/projects/Nuxtent.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
name: Nuxt Content | ||
--- | ||
|
||
It does some pretty awesome things. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<template> | ||
<div> | ||
<h1> {{ post.title }} </h1> | ||
<div v-html="post.body" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
async asyncData ({ app, route, payload }) { | ||
return { | ||
post: payload || await app.$content('/posts').get(route.path) | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<template> | ||
<section class="container"> | ||
<h1> Posts </h1> | ||
<ul> | ||
<li v-for="post in posts"> | ||
<nuxt-link :to="post.permalink">{{ post.title }}</nuxt-link> | ||
</li> | ||
</ul> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
async asyncData ({ app, payload }) { | ||
return { | ||
posts: payload || await app.$content('/posts').getAll() | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<template> | ||
<section class="home-container"> | ||
<h1>Nuxtent</h1> | ||
<nuxt-link to="/2015/first-post">See my first post</nuxt-link> | ||
<nuxt-link to="/archives">See all my posts</nuxt-link> | ||
<nuxt-link to="/projects/ency">See my first project</nuxt-link> | ||
<nuxt-link to="/projects">See all my projects</nuxt-link> | ||
</section> | ||
</template> | ||
|
||
<style> | ||
.home-container a { | ||
padding-right: 1rem; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<template> | ||
<section class="container"> | ||
<h1> Projects </h1> | ||
<ul> | ||
<li v-for="project in projects"> | ||
<nuxt-link :to="'/projects' + project.permalink">{{ project.name }}</nuxt-link> | ||
</li> | ||
</ul> | ||
<nuxt-child /> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
async asyncData ({ app, payload }) { | ||
return { | ||
projects: payload || await app.$content('/projects').getAll() | ||
} | ||
} | ||
} | ||
</script> |
16 changes: 16 additions & 0 deletions
16
tests/fixtures/multiple-content-types/pages/projects/_slug.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<template> | ||
<section class="container"> | ||
<h1> Project: {{ project.name }} </h1> | ||
<nuxtent-body :body="project.body" /> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
async asyncData ({ app, route, payload }) { | ||
return { | ||
project: payload || await app.$content('/projects').get(route.params.slug) | ||
} | ||
} | ||
} | ||
</script> |
6 changes: 6 additions & 0 deletions
6
tests/fixtures/multiple-content-types/pages/projects/index.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<template> | ||
<section class="container"> | ||
<h1> Project </h1> | ||
See all my projects! | ||
</section> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,15 @@ | |
"description": "nuxtent single content types example", | ||
"author": "Alid Castano <[email protected]>", | ||
"dependencies": { | ||
"@nuxtjs/axios": "^2.2.1", | ||
"nuxt": "^1.0.0-alpha.4" | ||
"@nuxtjs/axios": "^2.2.1" | ||
}, | ||
"scripts": { | ||
"dev": "nuxt", | ||
"build": "nuxt build", | ||
"start": "nuxt start", | ||
"generate": "nuxt generate" | ||
}, | ||
"devDependencies": { | ||
"nuxt": "^1.0.0-rc3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters