-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move post fetching and processing to api and model classes
* Remove some readmes
- Loading branch information
Morgan Brown
committed
Feb 9, 2019
1 parent
ab0dce3
commit 2f737d8
Showing
14 changed files
with
150 additions
and
89 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 @@ | ||
import axios from 'axios' | ||
|
||
export default { | ||
async bySha (sha) { | ||
const { data } = await axios.get(`https://api.github.com/repos/mhgbrown/nuxt-ghpages-blog-content/git/blobs/${sha}?access_token=${process.env.GITHUB_TOKEN}`) | ||
return data | ||
}, | ||
async all () { | ||
const postsPath = 'posts/' | ||
const url = `https://api.github.com/repos/mhgbrown/nuxt-ghpages-blog-content/git/trees/master?recursive=1&access_token=${process.env.GITHUB_TOKEN}` | ||
const { data } = await axios.get(url) | ||
return data.tree.reduce((memo, node) => { | ||
if (node.path.startsWith(postsPath)) { | ||
memo.push(node) | ||
} | ||
|
||
return memo | ||
}, []) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
import postsClient from '../api/posts' | ||
|
||
class Post { | ||
static async all () { | ||
const rawPosts = await postsClient.all() | ||
return rawPosts.map(rawPost => this._fromNode(rawPost)) | ||
} | ||
|
||
static async bySha (sha) { | ||
const rawPost = await postsClient.bySha(sha) | ||
return this._fromBlob(rawPost) | ||
} | ||
|
||
static _fromNode (node) { | ||
const post = new this(node) | ||
const pathPrefix = 'posts/' | ||
post.name = node.path.replace(pathPrefix, '') | ||
post.title = this._extractTitle(post.name) | ||
post.date = this._extractDate(post.name) | ||
return post | ||
} | ||
|
||
static _fromBlob (blob) { | ||
const post = new this(blob) | ||
post.content = '' | ||
return post | ||
} | ||
|
||
static _extractTitle (name) { | ||
return name.replace(/\.md$/, '') | ||
.replace(/^\d{4}-\d{1,2}-\d{1,2}-/, '') | ||
} | ||
|
||
static _extractDate (name) { | ||
return /^\d{4}-\d{1,2}-\d{1,2}/.exec(name)[0] | ||
} | ||
|
||
constructor (nodeOrBlob) { | ||
this.sha = nodeOrBlob.sha | ||
} | ||
} | ||
|
||
export default Post |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.