mirror of https://github.com/halo-dev/halo
Refactor gallery page.
parent
38eadc9674
commit
36f69cab39
|
@ -50,6 +50,9 @@ public class FreeMarkerAutoConfiguration {
|
|||
@Autowired
|
||||
private TagTagDirective tagTagDirective;
|
||||
|
||||
@Autowired
|
||||
private GalleryTagDirective galleryTagDirective;
|
||||
|
||||
@Autowired
|
||||
private RandomMethod randomMethod;
|
||||
|
||||
|
@ -71,6 +74,7 @@ public class FreeMarkerAutoConfiguration {
|
|||
configuration.setSharedVariable("menuTag", menuTagDirective);
|
||||
configuration.setSharedVariable("tagTag", tagTagDirective);
|
||||
configuration.setSharedVariable("postTag", postTagDirective);
|
||||
configuration.setSharedVariable("galleryTag",galleryTagDirective);
|
||||
configuration.setSharedVariable("randomMethod", randomMethod);
|
||||
configuration.setSharedVariable("recentPostsMethod", recentPostsMethod);
|
||||
configuration.setSharedVariable("recentCommentsMethod", recentCommentsMethod);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package run.halo.app.model.freemarker.tag;
|
||||
|
||||
import run.halo.app.service.CategoryService;
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import run.halo.app.model.support.HaloConst;
|
||||
import run.halo.app.service.CategoryService;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -18,8 +18,6 @@ import java.util.Map;
|
|||
@Component
|
||||
public class CategoryTagDirective implements TemplateDirectiveModel {
|
||||
|
||||
private static final String METHOD_KEY = "method";
|
||||
|
||||
private final CategoryService categoryService;
|
||||
|
||||
public CategoryTagDirective(CategoryService categoryService) {
|
||||
|
@ -30,8 +28,8 @@ public class CategoryTagDirective implements TemplateDirectiveModel {
|
|||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
|
||||
final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
|
||||
|
||||
if (params.containsKey(METHOD_KEY)) {
|
||||
String method = params.get(METHOD_KEY).toString();
|
||||
if (params.containsKey(HaloConst.METHOD_KEY)) {
|
||||
String method = params.get(HaloConst.METHOD_KEY).toString();
|
||||
switch (method) {
|
||||
case "list":
|
||||
env.setVariable("categories", builder.build().wrap(categoryService.listAll()));
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package run.halo.app.model.freemarker.tag;
|
||||
|
||||
import run.halo.app.service.CommentService;
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import run.halo.app.model.support.HaloConst;
|
||||
import run.halo.app.service.CommentService;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -18,8 +18,6 @@ import java.util.Map;
|
|||
@Component
|
||||
public class CommentTagDirective implements TemplateDirectiveModel {
|
||||
|
||||
private static final String METHOD_KEY = "method";
|
||||
|
||||
private final CommentService commentService;
|
||||
|
||||
public CommentTagDirective(CommentService commentService) {
|
||||
|
@ -30,8 +28,8 @@ public class CommentTagDirective implements TemplateDirectiveModel {
|
|||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
|
||||
final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
|
||||
|
||||
if (params.containsKey(METHOD_KEY)) {
|
||||
String method = params.get(METHOD_KEY).toString();
|
||||
if (params.containsKey(HaloConst.METHOD_KEY)) {
|
||||
String method = params.get(HaloConst.METHOD_KEY).toString();
|
||||
int top = Integer.parseInt(params.get("top").toString());
|
||||
switch (method) {
|
||||
case "latest":
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package run.halo.app.model.freemarker.tag;
|
||||
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import run.halo.app.model.support.HaloConst;
|
||||
import run.halo.app.service.GalleryService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Freemarker custom tag of gallery.
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019/4/21
|
||||
*/
|
||||
@Component
|
||||
public class GalleryTagDirective implements TemplateDirectiveModel {
|
||||
|
||||
private final GalleryService galleryService;
|
||||
|
||||
public GalleryTagDirective(GalleryService galleryService) {
|
||||
this.galleryService = galleryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
|
||||
final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
|
||||
|
||||
if (params.containsKey(HaloConst.METHOD_KEY)) {
|
||||
String method = params.get(HaloConst.METHOD_KEY).toString();
|
||||
switch (method) {
|
||||
case "list":
|
||||
env.setVariable("galleries", builder.build().wrap(galleryService.listAll()));
|
||||
break;
|
||||
case "listTeamVos":
|
||||
env.setVariable("galleries", builder.build().wrap(null));
|
||||
break;
|
||||
case "count":
|
||||
env.setVariable("count", builder.build().wrap(galleryService.count()));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
body.render(env.getOut());
|
||||
}
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
package run.halo.app.model.freemarker.tag;
|
||||
|
||||
import run.halo.app.service.LinkService;
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import run.halo.app.model.support.HaloConst;
|
||||
import run.halo.app.service.LinkService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
@ -17,8 +18,6 @@ import java.util.Map;
|
|||
@Component
|
||||
public class LinkTagDirective implements TemplateDirectiveModel {
|
||||
|
||||
private static final String METHOD_KEY = "method";
|
||||
|
||||
private final LinkService linkService;
|
||||
|
||||
public LinkTagDirective(LinkService linkService) {
|
||||
|
@ -29,8 +28,8 @@ public class LinkTagDirective implements TemplateDirectiveModel {
|
|||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
|
||||
final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
|
||||
|
||||
if (params.containsKey(METHOD_KEY)) {
|
||||
String method = params.get(METHOD_KEY).toString();
|
||||
if (params.containsKey(HaloConst.METHOD_KEY)) {
|
||||
String method = params.get(HaloConst.METHOD_KEY).toString();
|
||||
switch (method) {
|
||||
case "list":
|
||||
env.setVariable("links", builder.build().wrap(linkService.listAll()));
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package run.halo.app.model.freemarker.tag;
|
||||
|
||||
import run.halo.app.service.MenuService;
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import run.halo.app.model.support.HaloConst;
|
||||
import run.halo.app.service.MenuService;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -30,8 +30,8 @@ public class MenuTagDirective implements TemplateDirectiveModel {
|
|||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
|
||||
final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
|
||||
|
||||
if (params.containsKey(METHOD_KEY)) {
|
||||
String method = params.get(METHOD_KEY).toString();
|
||||
if (params.containsKey(HaloConst.METHOD_KEY)) {
|
||||
String method = params.get(HaloConst.METHOD_KEY).toString();
|
||||
switch (method) {
|
||||
case "list":
|
||||
env.setVariable("menus", builder.build().wrap(menuService.listAll()));
|
||||
|
|
|
@ -19,8 +19,6 @@ import java.util.Map;
|
|||
@Component
|
||||
public class PostTagDirective implements TemplateDirectiveModel {
|
||||
|
||||
private static final String METHOD_KEY = "method";
|
||||
|
||||
@Override
|
||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
|
||||
// TODO Complete article tag directive.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package run.halo.app.model.freemarker.tag;
|
||||
|
||||
import run.halo.app.model.support.HaloConst;
|
||||
import run.halo.app.service.TagService;
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.*;
|
||||
|
@ -17,8 +18,6 @@ import java.util.Map;
|
|||
@Component
|
||||
public class TagTagDirective implements TemplateDirectiveModel {
|
||||
|
||||
private static final String METHOD_KEY = "method";
|
||||
|
||||
private final TagService tagService;
|
||||
|
||||
public TagTagDirective(TagService tagService) {
|
||||
|
@ -29,8 +28,8 @@ public class TagTagDirective implements TemplateDirectiveModel {
|
|||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
|
||||
final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
|
||||
|
||||
if (params.containsKey(METHOD_KEY)) {
|
||||
String method = params.get(METHOD_KEY).toString();
|
||||
if (params.containsKey(HaloConst.METHOD_KEY)) {
|
||||
String method = params.get(HaloConst.METHOD_KEY).toString();
|
||||
switch (method) {
|
||||
case "list":
|
||||
env.setVariable("tags", builder.build().wrap(tagService.listAll()));
|
||||
|
|
|
@ -38,6 +38,11 @@ public class HaloConst {
|
|||
*/
|
||||
public static final String SUFFIX_FTL = ".ftl";
|
||||
|
||||
/**
|
||||
* Custom freemarker tag method key.
|
||||
*/
|
||||
public static final String METHOD_KEY = "method";
|
||||
|
||||
/**
|
||||
* Owo map. (Unmodified map)
|
||||
*/
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import run.halo.app.exception.NotFoundException;
|
||||
import run.halo.app.model.entity.Comment;
|
||||
import run.halo.app.model.entity.Gallery;
|
||||
import run.halo.app.model.entity.Post;
|
||||
import run.halo.app.model.enums.PostStatus;
|
||||
import run.halo.app.service.CommentService;
|
||||
|
@ -48,9 +47,7 @@ public class ContentPageController {
|
|||
* @return template path: themes/{theme}/gallery
|
||||
*/
|
||||
@GetMapping(value = "/gallery")
|
||||
public String gallery(Model model) {
|
||||
final List<Gallery> galleries = galleryService.listAll();
|
||||
model.addAttribute("galleries", galleries);
|
||||
public String gallery() {
|
||||
return themeService.render("gallery");
|
||||
}
|
||||
|
||||
|
|
|
@ -23,15 +23,17 @@
|
|||
</ul>
|
||||
</header>
|
||||
<section id="thumbnails">
|
||||
<#if galleries?size gt 0>
|
||||
<#list galleries as gallery>
|
||||
<article>
|
||||
<a class="thumbnail" href="${gallery.url}" data-position="left center"><img src="${gallery.thumbnail}" alt="${gallery.description}" /></a>
|
||||
<h2>${gallery.name}</h2>
|
||||
<p>${gallery.takeTime!}</p>
|
||||
</article>
|
||||
</#list>
|
||||
</#if>
|
||||
<@galleryTag method="list">
|
||||
<#if galleries?size gt 0>
|
||||
<#list galleries as gallery>
|
||||
<article>
|
||||
<a class="thumbnail" href="${gallery.url}" data-position="left center"><img src="${gallery.thumbnail}" alt="${gallery.description}" /></a>
|
||||
<h2>${gallery.name}</h2>
|
||||
<p>${gallery.takeTime!}</p>
|
||||
</article>
|
||||
</#list>
|
||||
</#if>
|
||||
</@galleryTag>
|
||||
</section>
|
||||
<footer id="footer">
|
||||
<ul class="copyright">
|
||||
|
|
Loading…
Reference in New Issue