轉載請附原文鏈接:http://blog.fandong.me/2017/09/21/GitHub-Pages-JSON/
前言
很多人在github.io上寄存了自己的博客,比如我
同時還有這么一小撮人,想在App展示博客文章的列表,比如我
那么問題來了,如何使用GitHub生成的文章列表生成可用于App上呢,這里使用了常用的JSON數據額格式
第一步
在根目錄創建.json格式文件
比如getArticleList.json
第二步
開始書寫代碼
因為我的文章頭部一般都寫這幾個參數
---
layout: post
title: "GitHub Pages 博客文章導出JSON供App使用方法"
subtitle: ""
date: 2017-09-21 11:32:00.000000000 +08:00
author: "范東"
header-img: "img/post-bg-ios9-web.jpg"
catalog: true
tags:
- GitHub
- GitHub.io
- GitHub Pages
---
所以我們獲取字段的時候一般也就獲取這些字段(以下為getArticleList.json的內容)
---
layout: nil
---
[{% for post in site.posts limit:1000 %}
{
"title":"{{post.title}}",
"url":"{{site.url}}{{post.url}}",
"date":"{{post.date|date_to_string}}",
"author":"{{post.author}}",
"header-img":"{{post.header-img}}",
"subtitle":"{{post.subtitle}}",
"tags":"{{post.tags}}",
"catalog":"{{post.catalog}}"
}{% if forloop.last == false %},{% endif %}
{% endfor %}
]
第三步
上傳getArticleList.json到你github.io的倉庫地址
第四步
驗證
點擊如下鏈接
http://fandongtongxue.github.io/getArticleList.json