Comparing version 0.7.6 to 0.7.7
@@ -12,6 +12,9 @@ import { Config } from "../config"; | ||
getPosts(): Promise<Array<Post>>; | ||
getPublishedPosts(): Promise<Array<Post>>; | ||
getPostsByCount(count: number): Promise<Array<Post>>; | ||
getPublishedPostsByCount(count: number): Promise<Array<Post>>; | ||
getTag(name: string): Promise<Tag | undefined>; | ||
getTags(): Promise<Array<Tag>>; | ||
getPublishedTags(): Promise<Array<Tag>>; | ||
getProvider(): DataProviderInterface; | ||
} |
@@ -28,9 +28,7 @@ "use strict"; | ||
result = await this.getProvider().getPosts(); | ||
if (result) { | ||
//sort | ||
let arraySort = require("array-sort"); | ||
result = new arraySort(result, "date", { reverse: true }); | ||
//cache | ||
await this.cache.setPosts(cacheKey, result); | ||
} | ||
//sort | ||
let arraySort = require("array-sort"); | ||
result = new arraySort(result, "date", { reverse: true }); | ||
//cache | ||
await this.cache.setPosts(cacheKey, result); | ||
} | ||
@@ -42,2 +40,19 @@ else { | ||
} | ||
async getPublishedPosts() { | ||
let result = new Array(); | ||
let cacheKey = "get-published-posts"; | ||
let posts = await this.cache.getPosts(cacheKey); | ||
if (!posts) { | ||
result = await this.getProvider().getPublishedPosts(); | ||
//sort | ||
let arraySort = require("array-sort"); | ||
result = new arraySort(result, "date", { reverse: true }); | ||
//cache | ||
await this.cache.setPosts(cacheKey, result); | ||
} | ||
else { | ||
result = posts; | ||
} | ||
return result; | ||
} | ||
async getPostsByCount(count) { | ||
@@ -56,2 +71,15 @@ let result = await this.getPosts(); | ||
} | ||
async getPublishedPostsByCount(count) { | ||
let result = await this.getPublishedPosts(); | ||
let list = new Array(); | ||
let currentCount = 0; | ||
result.forEach((post) => { | ||
if (currentCount < count) { | ||
list.push(post); | ||
currentCount++; | ||
} | ||
}); | ||
result = list; | ||
return result; | ||
} | ||
//tags | ||
@@ -77,6 +105,4 @@ async getTag(name) { | ||
let arraySort = require("array-sort"); | ||
result = new arraySort(result, "name", { reverse: false }); | ||
if (result) { | ||
await this.cache.setTags(cacheKey, result); | ||
} | ||
result = new arraySort(result, "id", { reverse: false }); | ||
await this.cache.setTags(cacheKey, result); | ||
} | ||
@@ -88,2 +114,18 @@ else { | ||
} | ||
async getPublishedTags() { | ||
let result = new Array(); | ||
let cacheKey = "get-published-tags"; | ||
let tags = await this.cache.getTags(cacheKey); | ||
if (!tags) { | ||
result = await this.getProvider().getPublishedTags(); | ||
//sort | ||
let arraySort = require("array-sort"); | ||
result = new arraySort(result, "id", { reverse: false }); | ||
await this.cache.setTags(cacheKey, result); | ||
} | ||
else { | ||
result = tags; | ||
} | ||
return result; | ||
} | ||
getProvider() { | ||
@@ -90,0 +132,0 @@ let result = undefined; |
@@ -83,5 +83,5 @@ "use strict"; | ||
post.tags.forEach(tagName => { | ||
let tag = result.find(t => this.formatToKey(t.name) === this.formatToKey(tagName)); | ||
let tag = result.find(t => t.id === new tag_1.Tag(tagName).id); | ||
if (tag == null) { | ||
tag = new tag_1.Tag(this.formatToKey(tagName)); | ||
tag = new tag_1.Tag(tagName); | ||
result.push(tag); | ||
@@ -88,0 +88,0 @@ } |
@@ -14,7 +14,10 @@ "use strict"; | ||
fs.ensureDirSync(output); | ||
let posts = await dataStore.getPosts(); | ||
let tags = await dataStore.getTags(); | ||
let posts = await dataStore.getPublishedPosts(); | ||
let unpublishedPosts = await dataStore.getPosts(); | ||
let tags = await dataStore.getPublishedTags(); | ||
let unpublishedTags = await dataStore.getTags(); | ||
//posts | ||
let previousPost; | ||
let nextPost; | ||
//published posts | ||
posts.forEach(async (post, index) => { | ||
@@ -38,2 +41,23 @@ if (index === 0) { | ||
}); | ||
//unpublished posts | ||
unpublishedPosts.forEach(async (post, index) => { | ||
if (index === 0) { | ||
previousPost = posts[posts.length - 1]; | ||
} | ||
else { | ||
previousPost = posts[index - 1]; | ||
} | ||
if (index === posts.length - 1) { | ||
nextPost = posts[0]; | ||
} | ||
else { | ||
nextPost = posts[index + 1]; | ||
} | ||
if (post.published === false) { | ||
let postHtml = await this.renderPost(post, previousPost, nextPost, unpublishedTags, config); | ||
let postPath = output + "/" + post.id; | ||
fs.ensureDirSync(postPath); | ||
fs.writeFileSync(postPath + "/index.html", postHtml); | ||
} | ||
}); | ||
//tags | ||
@@ -54,4 +78,4 @@ fs.ensureDirSync(output + "/tags/"); | ||
let result = ""; | ||
let postList = await dataStore.getPostsByCount(config.indexCount); | ||
let tagList = await dataStore.getTags(); | ||
let postList = await dataStore.getPublishedPostsByCount(config.indexCount); | ||
let tagList = await dataStore.getPublishedTags(); | ||
let source = this.getHomeTemplate(config); | ||
@@ -58,0 +82,0 @@ result = this.renderTemplate(source, { tags: tagList, posts: postList }, config); |
@@ -8,9 +8,8 @@ "use strict"; | ||
this.posts = new Array(); | ||
this.name = name; | ||
this.name = name.trim(); | ||
} | ||
get id() { | ||
let result = ""; | ||
let simpleUrl = this.name.toLowerCase().replace(/[^a-z0-9+]+/gi, " ").trim(); | ||
simpleUrl = simpleUrl.split(" ").join("-"); | ||
result = simpleUrl; | ||
result = this.name.toLowerCase().replace(/[^a-z0-9+]+/gi, " ").trim(); | ||
result = result.split(" ").join("-"); | ||
return result; | ||
@@ -17,0 +16,0 @@ } |
{ | ||
"name": "writr", | ||
"version": "0.7.6", | ||
"version": "0.7.7", | ||
"description": "A Simple to Use Markdown Blog", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72849
1106