前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Gatsby入门指南—添加博客文章列表(3)

Gatsby入门指南—添加博客文章列表(3)

原创
作者头像
前端大彬哥
发布2019-05-28 12:34:25
5640
发布2019-05-28 12:34:25
举报
文章被收录于专栏:大前端666

1.查数据

代码语言:javascript
复制
{
  allMarkdownRemark(sort: {order: DESC, fields: [frontmatter___date]}) {
    edges {
      node {
        frontmatter {
          title
          path
          date
          excerpt
        }
      }
    }
  }
}

如图所示:

2.套页面

打开index.js

代码语言:javascript
复制
import React from "react"
import Header from '../components/header'
import { Link,graphql } from 'gatsby'
​
const Layout = ({ data }) => {
  const { edges } = data.allMarkdownRemark;
  return (
    <div>
      <Header />
      <div style={{
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center'
      }}>
        {
          edges.map(edge => {
            const { frontmatter } = edge.node;
            return (
              <div key={frontmatter.path}>
                <Link to={frontmatter.path}>
                 {frontmatter.title}
                </Link>
              </div>
            )
          })
        }
      </div>
    </div>
  )
}
export const query = graphql`
query{
    allMarkdownRemark (sort:{
      order:DESC,
      fields:[frontmatter___date]
    }){
      edges {
        node {
          frontmatter {
            title
            path
            date
            excerpt
          }
        }
      } 
  }
}
`;
export default Layout;

打开首页,看到文章列表就大功告成了。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1.查数据
    • 如图所示:
    • 2.套页面
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档