Skip to content

Commit 1543dc6

Browse files
committed
fix counting tag posts
1 parent 4a25f3f commit 1543dc6

10 files changed

Lines changed: 65 additions & 28 deletions

File tree

.bowerrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "src/main/resources/resources/bower_components"
3+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ bin
55
scripts
66
production_app.properties
77
*.iml
8+
src/main/resources/resources/bower_components

bower.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "springblog",
3+
"version": "0.0.0",
4+
"appPath": "src/main/resources",
5+
"testPath": "src/test/javascript/spec",
6+
"dependencies": {
7+
"jquery": "2.1.4",
8+
"marked": "0.3.5",
9+
"simple-module": "2.0.6",
10+
"simple-hotkeys": "1.0.3",
11+
"simditor": "2.3.5",
12+
"simditor-markdown": "1.1.2",
13+
"to-markdown": "1.3.0"
14+
},
15+
"devDependencies": {}
16+
}

src/main/java/com/raysmond/blog/controllers/TagController.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ public class TagController {
3737

3838
@RequestMapping(value = "", method = GET)
3939
public String index(Model model){
40-
// TODO show all tags
41-
42-
List<Map<String, Long>> counts = postService.countPostsByTags();
43-
44-
model.addAttribute("tags", counts);
45-
40+
model.addAttribute("tags", postService.countPostsByTags());
4641
return "tags/index";
4742
}
4843

src/main/java/com/raysmond/blog/repositories/PostRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public interface PostRepository extends JpaRepository<Post, Long> {
3434
"WHERE p.postStatus = :status " +
3535
"GROUP BY t.id " +
3636
"ORDER BY tag_count DESC")
37-
List<Map<String, Long>> countPostsByTags(@Param("status") PostStatus status);
37+
List<Object[]> countPostsByTags(@Param("status") PostStatus status);
3838
}
3939

src/main/java/com/raysmond/blog/services/PostService.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ public Post getPost(Long postId) {
5050

5151
Post post = postRepository.findOne(postId);
5252

53-
if (post == null){
53+
if (post == null) {
5454
throw new NotFoundException("Post with id " + postId + " is not found.");
5555
}
5656

5757
return post;
5858
}
5959

6060
@Cacheable(CACHE_NAME)
61-
public Post getPublishedPostByPermalink(String permalink){
61+
public Post getPublishedPostByPermalink(String permalink) {
6262
logger.debug("Get post with permalink " + permalink);
6363

6464
Post post = postRepository.findByPermalinkAndPostStatus(permalink, PostStatus.PUBLISHED);
6565

66-
if (post == null){
66+
if (post == null) {
6767
throw new NotFoundException("Post with permalink '" + permalink + "' is not found.");
6868
}
6969

@@ -73,7 +73,7 @@ public Post getPublishedPostByPermalink(String permalink){
7373
@Caching(evict = {
7474
@CacheEvict(value = CACHE_NAME_ARCHIVE, allEntries = true),
7575
@CacheEvict(value = CACHE_NAME_PAGE, allEntries = true),
76-
@CacheEvict(value = CACHE_NAME_COUNTS, allEntries = true)
76+
@CacheEvict(value = CACHE_NAME_COUNTS, allEntries = true)
7777
})
7878
public Post createPost(Post post) {
7979
if (post.getPostFormat() == PostFormat.MARKDOWN) {
@@ -86,10 +86,10 @@ public Post createPost(Post post) {
8686
@Caching(evict = {
8787
@CacheEvict(value = CACHE_NAME, key = "#post.id"),
8888
@CacheEvict(value = CACHE_NAME, key = "#post.permalink", condition = "#post.permalink != null"),
89-
@CacheEvict(value = CACHE_NAME_TAGS, key = "#post.id.toString().concat('-tags')"),
89+
@CacheEvict(value = CACHE_NAME_TAGS, key = "#post.id.toString().concat('-tags')"),
9090
@CacheEvict(value = CACHE_NAME_ARCHIVE, allEntries = true),
9191
@CacheEvict(value = CACHE_NAME_PAGE, allEntries = true),
92-
@CacheEvict(value = CACHE_NAME_COUNTS, allEntries = true)
92+
@CacheEvict(value = CACHE_NAME_COUNTS, allEntries = true)
9393
})
9494
public Post updatePost(Post post) {
9595
if (post.getPostFormat() == PostFormat.MARKDOWN) {
@@ -105,7 +105,7 @@ public Post updatePost(Post post) {
105105
@CacheEvict(value = CACHE_NAME_TAGS, key = "#post.id.toString().concat('-tags')"),
106106
@CacheEvict(value = CACHE_NAME_ARCHIVE, allEntries = true),
107107
@CacheEvict(value = CACHE_NAME_PAGE, allEntries = true),
108-
@CacheEvict(value = CACHE_NAME_COUNTS, allEntries = true)
108+
@CacheEvict(value = CACHE_NAME_COUNTS, allEntries = true)
109109
})
110110
public void deletePost(Post post) {
111111
postRepository.delete(post);
@@ -127,7 +127,7 @@ public List<Post> getArchivePosts() {
127127
}
128128

129129
@Cacheable(value = CACHE_NAME_TAGS, key = "#post.id.toString().concat('-tags')")
130-
public List<Tag> getPostTags(Post post){
130+
public List<Tag> getPostTags(Post post) {
131131
logger.debug("Get tags of post " + post.getId());
132132

133133
List<Tag> tags = new ArrayList<>();
@@ -140,7 +140,7 @@ public List<Tag> getPostTags(Post post){
140140
}
141141

142142

143-
private Post extractPostMeta(Post post){
143+
private Post extractPostMeta(Post post) {
144144
Post archivePost = new Post();
145145
archivePost.setId(post.getId());
146146
archivePost.setTitle(post.getTitle());
@@ -173,38 +173,38 @@ public Post createAboutPage() {
173173
return createPost(post);
174174
}
175175

176-
public Set<Tag> parseTagNames(String tagNames){
176+
public Set<Tag> parseTagNames(String tagNames) {
177177
Set<Tag> tags = new HashSet<>();
178178

179-
if (tagNames != null && !tagNames.isEmpty()){
179+
if (tagNames != null && !tagNames.isEmpty()) {
180180
tagNames = tagNames.toLowerCase();
181181
String[] names = tagNames.split("\\s*,\\s*");
182-
for (String name : names){
182+
for (String name : names) {
183183
tags.add(tagService.findOrCreateByName(name));
184184
}
185185
}
186186

187187
return tags;
188188
}
189189

190-
public String getTagNames(Set<Tag> tags){
190+
public String getTagNames(Set<Tag> tags) {
191191
if (tags == null || tags.isEmpty())
192192
return "";
193193

194194
StringBuilder names = new StringBuilder();
195195
tags.forEach(tag -> names.append(tag.getName()).append(","));
196-
names.deleteCharAt(names.length()-1);
196+
names.deleteCharAt(names.length() - 1);
197197

198198
return names.toString();
199199
}
200200

201201
// cache or not?
202-
public Page<Post> findPostsByTag(String tagName, int page, int pageSize){
202+
public Page<Post> findPostsByTag(String tagName, int page, int pageSize) {
203203
return postRepository.findByTag(tagName, new PageRequest(page, pageSize, Sort.Direction.DESC, "createdAt"));
204204
}
205205

206206
@Cacheable(value = CACHE_NAME_COUNTS, key = "#root.method.name")
207-
public List<Map<String, Long>> countPostsByTags(){
207+
public List<Object[]> countPostsByTags() {
208208
logger.debug("Count posts group by tags.");
209209

210210
return postRepository.countPostsByTags(PostStatus.PUBLISHED);

src/main/resources/resources/css/theme-light.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ a{
2222

2323
/* override typo css */
2424
h1, h2, h3, h4, h5, h6{
25-
color: #75889E;
25+
color: #47596D;
26+
-webkit-font-smoothing: normal;
2627
}
2728
.typo a{
2829
color: #337ab7;
@@ -227,9 +228,10 @@ form input, form button{
227228
}
228229

229230
.post-item a > h2{
230-
font-size: 1.4em;
231+
font-size: 1.1em;
231232
margin-top: 0;
232233
color: #515862;
234+
font-weight: 400;
233235
}
234236

235237
.post-item .meta{

src/main/resources/templates/admin/layout/head.jade

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ title #{App.getSiteName()}
99
link(rel='stylesheet', type='text/css', href='/webjars/bootstrap/3.3.5/css/bootstrap.min.css')
1010
link(rel='stylesheet', type='text/css', href='/webjars/font-awesome/4.3.0-3/css/font-awesome.min.css')
1111
link(rel="stylesheet", type='text/css', href="/css/admin/admin.css")
12+
link(rel="stylesheet", href="/bower_components/simditor/styles/simditor.css")
13+
link(rel="stylesheet", href="/bower_components/simditor-markdown/styles/simditor-markdown.css")
1214

1315
script(src="/webjars/jquery/2.1.4/jquery.min.js")
1416
script(src="/webjars/bootstrap/3.3.5/js/bootstrap.min.js")
1517
script(src="/vendors/bootstrap-paginator-1.0.2/js/bootstrap-paginator.min.js")
18+
script(src="/bower_components/marked/marked.min.js")
19+
script(src="/bower_components/simple-module/lib/module.js")
20+
script(src="/bower_components/simple-hotkeys/lib/hotkeys.js")
21+
script(src="/bower_components/to-markdown/dist/to-markdown.js")
22+
script(src="/bower_components/simditor/lib/simditor.js")
23+
script(src="/bower_components/simditor-markdown/lib/simditor-markdown.js")

src/main/resources/templates/admin/posts/edit.jade

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,22 @@ block content
5252
script
5353
var editor = ace.edit("content-editor");
5454
editor.setTheme("ace/theme/github");
55-
55+
5656
var MarkdownMode = ace.require("ace/mode/markdown").Mode;
5757
editor.getSession().setMode(new MarkdownMode());
58-
58+
5959
editor.getSession().setUseWrapMode(true);
60-
60+
6161
$("form").submit(function(){
6262
$("#content").val(editor.getValue());
6363
return true;
6464
});
65+
66+
//$(function() {
67+
// var editor = new Simditor({
68+
// textarea: $('#content'),
69+
// markdown: true,
70+
// toolbar: ['title', 'bold', 'italic', 'underline', 'strikethrough', 'color', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link', 'image', 'hr', '|', 'indent', 'outdent', 'alignment', '|', 'markdown']
71+
// });
72+
//});
73+

src/main/resources/templates/home/about.jade

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ block content
1111
.post
1212
.content
1313
!{about.getRenderedContent()}
14+
15+
.comments
16+
include ../fragments/disqus

0 commit comments

Comments
 (0)