Skip to content

Commit

Permalink
feat(blog): add breadcrumb (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadow81627 committed Jan 27, 2020
1 parent a0b186a commit 7327142
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 25 deletions.
28 changes: 28 additions & 0 deletions components/layout/breadcrumb.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<b-breadcrumb :items="breadcrumbs"></b-breadcrumb>
</template>

<script>
export default {
computed: {
breadcrumbs() {
// console.log(this.$route);
const here = this.$route.path.split('/').slice(1);
const parts = [{ text: 'Home', to: '/' }];
for (let i = 0; i < here.length; i++) {
const part = here[i];
const text =
part.charAt(0).toUpperCase() + part.substr(1).toLowerCase();
const to = '/' + here.slice(0, i + 1).join('/');
parts.push({ text, to });
}
return parts;
},
},
};
</script>

<style></style>
17 changes: 11 additions & 6 deletions pages/blog/_slug.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<template>
<section class="util__container">
<div v-editable="story.content" class="blog">
<h1>{{ story.content.name }}</h1>
<richtext class="blog__body" :text="story.content.body"></richtext>
</div>
</section>
<div>
<breadcrumb></breadcrumb>
<section class="util__container">
<div v-editable="story.content" class="blog">
<h1>{{ story.content.name }}</h1>
<richtext class="blog__body" :text="story.content.body"></richtext>
</div>
</section>
</div>
</template>

<script>
import Breadcrumb from '@/components/layout/breadcrumb';
import Richtext from '@/components/richtext.vue';
import storyblokLivePreview from '@/mixins/storyblokLivePreview';
export default {
components: {
Richtext,
Breadcrumb,
},
mixins: [storyblokLivePreview],
asyncData(context) {
Expand Down
43 changes: 24 additions & 19 deletions pages/blog/index.vue
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
<template>
<section class="util__container">
<div
v-for="blogPost in data.stories"
:key="blogPost.content._uid"
class="blog__overview"
>
<h2>
<nuxt-link class="blog__detail-link" :to="'/' + blogPost.full_slug">
{{ blogPost.content.name }}
</nuxt-link>
</h2>
<small>
{{ blogPost.published_at }}
</small>
<p>
{{ blogPost.content.intro }}
</p>
</div>
</section>
<div>
<Breadcrumb></Breadcrumb>
<section class="util__container">
<div
v-for="blogPost in data.stories"
:key="blogPost.content._uid"
class="blog__overview"
>
<h2>
<nuxt-link class="blog__detail-link" :to="'/' + blogPost.full_slug">
{{ blogPost.content.name }}
</nuxt-link>
</h2>
<small>
{{ blogPost.published_at }}
</small>
<p>
{{ blogPost.content.intro }}
</p>
</div>
</section>
</div>
</template>

<script>
import Breadcrumb from '@/components/layout/breadcrumb';
export default {
components: { Breadcrumb },
asyncData(context) {
const version =
context.query._storyblok || context.isDev ? 'draft' : 'published';
Expand Down

1 comment on commit 7327142

@vercel
Copy link

@vercel vercel bot commented on 7327142 Jan 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.