Skip to content

Commit

Permalink
Merge pull request #11 from auroral-ui/beta
Browse files Browse the repository at this point in the history
Add feature to use uid as slug and sortting of tags in decending order
  • Loading branch information
bennyxguo authored Aug 18, 2023
2 parents 8a81d46 + b08c750 commit 1005918
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
14 changes: 12 additions & 2 deletions lib/generators/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class TagGenerator {
}
}

sortTags() {
this.data = Object.assign(this.data, []).sort(function (a, b) {
return b.posts.length - a.posts.length;
});
}

reduceTags() {
if (this.count() <= 0) return;
const tags = this.data;
Expand All @@ -36,7 +42,7 @@ class TagGenerator {
data: {
name: item.name,
slug: item.slug,
count: item.posts.length,
count: item.count ?? item.posts.length,
path: 'api/tags/' + item.slug + '.json',
postlist: item.posts.map((post) => {
return postListMapper(post, configs);
Expand All @@ -56,7 +62,11 @@ class TagGenerator {
} else {
data.push({
path: 'api/tags.json',
data: JSON.stringify(this.data.map(tagMapper))
data: JSON.stringify(
this.data.map(tagMapper).sort(function (a, b) {
return b.count - a.count;
})
)
});
data = data.concat(this.data.map(tagPageMapper));
}
Expand Down
13 changes: 10 additions & 3 deletions lib/helpers/mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ const {
function postMapper(post, configs) {
const abstract = post.abstracts || post.content;
const abstractLength = post.abstracts ? post.abstracts.length : post.preview || 80;
const uid = generateUid('post_uid___' + post.title);
const pathSlug =
configs.theme_config.site.pathSlug !== undefined
? configs.theme_config.site.pathSlug === 'uid'
? uid
: post.slug
: post.slug;
return {
title: post.title,
uid: generateUid('post_uid___' + post.title),
slug: post.slug,
uid: uid,
slug: pathSlug,
date: post.date,
updated: post.updated,
comments: post.comments,
path: 'api/articles/' + post.slug + '.json',
path: `api/articles/${pathSlug}.json`,
keywords: configs.keywords,
cover: post.cover || fetchCovers(post.content),
content: post.content,
Expand Down

0 comments on commit 1005918

Please sign in to comment.