Skip to content

Commit 8cfa86f

Browse files
Merge pull request #9 from ButterCMS/first-revision
LGTM - going to merge in, deploy, and run 1 last time
2 parents 6aac360 + 0de7bdf commit 8cfa86f

File tree

21 files changed

+118
-90
lines changed

21 files changed

+118
-90
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,20 @@ To fetch your ButterCMS content, add your API token as an environment variable.
3737

3838
Build the project with the following command
3939

40-
`$ mvn install -DskipTests`
40+
`$ mvn install`
4141

4242
### 4. Run the project
4343

4444
To view the app in the browser, you'll need to run the local development server:
4545

4646
`$ mvn spring-boot:run`
4747

48+
Alternatively, you can run it directly via the `java` command
49+
50+
`$ java -jar target/spring-starter-buttercms-*.jar`
51+
52+
where the file name `spring-starter-buttercms` will be appended by the value of the version tag `<version>` in [pom.xml](pom.xml)
53+
4854
Congratulations! Your starter project is now live. To view your project,
4955
point your browser to [http://localhost:8080](http://localhost:8080).
5056

@@ -61,4 +67,4 @@ and institute a full content workflow connected to your ButterCMS account. Smoot
6167

6268
By default, your starter project is set up to allow previewing of draft changes
6369
saved in your ButterCMS.com account. To disable this functionality, set the
64-
following value in your .env file: JAVA_BUTTER_CMS_PREVIEW=false
70+
following value in your .env file: `JAVA_BUTTER_CMS_PREVIEW=false`

src/main/java/com/buttercms/springstarterbuttercms/controller/BlogController.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
import com.buttercms.springstarterbuttercms.service.BlogService;
55
import org.springframework.stereotype.Controller;
66
import org.springframework.ui.Model;
7-
import org.springframework.web.bind.annotation.GetMapping;
8-
import org.springframework.web.bind.annotation.PathVariable;
9-
import org.springframework.web.bind.annotation.PostMapping;
10-
import org.springframework.web.bind.annotation.RequestParam;
7+
import org.springframework.web.bind.annotation.*;
118

129
@Controller
1310
public class BlogController {
@@ -67,8 +64,8 @@ public String blogByTag(@PathVariable String tagSlug, Model model) {
6764
return "blogs";
6865
}
6966

70-
@PostMapping("/blog/search")
71-
public String search(@RequestParam String searchTerm, Model model) {
67+
@GetMapping(value = "/blog/search")
68+
public String search(@RequestParam(name = "q", required = false, defaultValue = "") String searchTerm, Model model) {
7269
BlogsDto blogsDto = blogService.searchBlogs(searchTerm);
7370
model.addAttribute("posts", blogsDto.getPosts());
7471
model.addAttribute("categories", blogsDto.getCategories());

src/main/java/com/buttercms/springstarterbuttercms/controller/IndexController.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.buttercms.springstarterbuttercms.controller;
22

33
import com.buttercms.springstarterbuttercms.controller.dto.LandingPageDto;
4+
import com.buttercms.springstarterbuttercms.model.landingpage.Field;
5+
import com.buttercms.springstarterbuttercms.model.landingpage.Fields;
46
import com.buttercms.springstarterbuttercms.model.landingpage.Section;
57
import com.buttercms.springstarterbuttercms.model.landingpage.Seo;
68
import com.buttercms.springstarterbuttercms.service.PageCollectionService;
@@ -22,13 +24,12 @@ public IndexController(PageCollectionService pageCollectionService) {
2224

2325
@GetMapping(value = {"/","/landing-page/{slug}"})
2426
public String index(@PathVariable(required = false) String slug, Model model) {
25-
LandingPageDto landingPage = pageCollectionService.getLandingPage();
27+
LandingPageDto landingPage = pageCollectionService.getLandingPage("landing-page", slug);
2628
Seo seo = landingPage.getFields().getSeo();
27-
List<Section> sections = landingPage.extractSections(landingPage.getFields());
2829
model.addAttribute("posts", landingPage.getPosts());
2930
model.addAttribute("seoTitle", seo.getTitle());
3031
model.addAttribute("seoDescription", seo.getDescription());
31-
model.addAttribute("sections", sections);
32+
model.addAttribute("fields", landingPage.getFields().getFields());
3233
return "index";
3334
}
3435
}

src/main/java/com/buttercms/springstarterbuttercms/controller/dto/ConstDtoValues.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class ConstDtoValues {
44
public static String BLOG_SEO_TITLE = "Sample Blog - All Posts";
55
public static String BLOG_SEO_DESCRIPTION = "Sample blog powered by ButterCMS, showing all posts.";
66
public static String BLOG_CATEGORY_SEO_TITLE = "Sample Blog - category: ";
7-
public static String BLOG_CATEGORY_SEO_DESCRIPTION = "Sample Blog - category: ";
7+
public static String BLOG_CATEGORY_SEO_DESCRIPTION = "Sample blog powered by ButterCMS, showing category: ";
88
public static String BLOG_TAG_SEO_TITLE = "Sample Blog - tag: ";
99
public static String BLOG_TAG_SEO_DESCRIPTION = "Sample blog powered by ButterCMS, showing tag: ";
1010
public static String BLOG_SEARCH_SEO_TITLE = "Sample Blog - search results for ";

src/main/java/com/buttercms/springstarterbuttercms/model/landingpage/Field.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
package com.buttercms.springstarterbuttercms.model.landingpage;
22

3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
34
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.annotation.JsonSubTypes;
6+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
47

58
public class Field {
69
private String type;
710
@JsonProperty("fields")
11+
@JsonIgnoreProperties(ignoreUnknown = true)
12+
@JsonTypeInfo(
13+
use = JsonTypeInfo.Id.NAME,
14+
include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
15+
property = "type",
16+
visible = true
17+
)
18+
@JsonSubTypes({
19+
@JsonSubTypes.Type(value = BasicSection.class, name = "hero"),
20+
@JsonSubTypes.Type(value = ImageSection.class, name = "two_column_with_image"),
21+
@JsonSubTypes.Type(value = FeaturesSection.class, name = "features"),
22+
@JsonSubTypes.Type(value = TestimonialsSection.class, name = "testimonials")
23+
})
824
private Section section;
925

1026
public String getType() {
Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
package com.buttercms.springstarterbuttercms.model.landingpage;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
43
import com.fasterxml.jackson.annotation.JsonProperty;
5-
import com.fasterxml.jackson.annotation.JsonSubTypes;
6-
import com.fasterxml.jackson.annotation.JsonTypeInfo;
74

8-
@JsonIgnoreProperties(ignoreUnknown = true)
9-
@JsonTypeInfo(
10-
use = JsonTypeInfo.Id.NAME,
11-
include = JsonTypeInfo.As.EXISTING_PROPERTY,
12-
property = "scroll_anchor_id",
13-
visible = true
14-
)
15-
@JsonSubTypes({
16-
@JsonSubTypes.Type(value = BasicSection.class, name = "home"),
17-
@JsonSubTypes.Type(value = ImageSection.class, name = "about"),
18-
@JsonSubTypes.Type(value = ImageSection.class, name = "tryit"),
19-
@JsonSubTypes.Type(value = FeaturesSection.class, name = "features"),
20-
@JsonSubTypes.Type(value = TestimonialsSection.class, name = "testimonials")
21-
})
5+
226
public abstract class Section {
237
@JsonProperty("scroll_anchor_id")
248
private String scrollAnchorId;
@@ -37,4 +21,4 @@ public String getScrollAnchorId() {
3721
public void setScrollAnchorId(String scrollAnchorId) {
3822
this.scrollAnchorId = scrollAnchorId;
3923
}
40-
}
24+
}

src/main/java/com/buttercms/springstarterbuttercms/service/PageCollectionService.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@ public class PageCollectionService {
1616

1717
private final IButterCMSClient butterCMSClient;
1818

19+
private final static String DEFAULT_LANDING_PAGE = "landing-page-with-components";
20+
1921
public PageCollectionService(IButterCMSClient butterCMSClient) {
2022
this.butterCMSClient = butterCMSClient;
2123
}
2224

23-
public LandingPageDto getLandingPage() {
25+
public LandingPageDto getLandingPage(String pageType, String slug) {
26+
slug = slug == null ? DEFAULT_LANDING_PAGE : slug;
2427
Map<String, String> queryParams = new HashMap<String, String>() {{
2528
put("page", "1");
2629
put("page_size", "2");
2730
}};
2831
List<Post> posts = butterCMSClient.getPosts(queryParams).getData();
2932
Fields landingPage = butterCMSClient.getPage(
30-
"*",
31-
"landing-page-with-components",
33+
pageType,
34+
slug,
3235
new HashMap<>(),
3336
Fields.class
3437
).getData().getFields();

src/main/resources/static/js/section-menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
var val = currLink.getAttribute('href').replaceAll("/", "");
1010
var refElement = document.querySelector(val);
1111
var scrollTopMinus = scrollPos + 73;
12-
if (refElement.offsetTop <= scrollTopMinus && (refElement.offsetTop + refElement.offsetHeight > scrollTopMinus)) {
12+
if (refElement && refElement.offsetTop <= scrollTopMinus && (refElement.offsetTop + refElement.offsetHeight > scrollTopMinus)) {
1313
document.querySelector('.page-scroll').classList.remove('active');
1414
currLink.classList.add('active');
1515
} else {

src/main/resources/templates/fragments/blog/categories.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<body>
44
<div class="widget categories-widget">
55
<h5 class="widget-title">Categories</h5>
6-
<ul th:each="category: ${categories}" class="categories-list">
7-
<li>
8-
<a th:text="${category.name}" th:href="|/blog/category/${category.slug}|"></a>
6+
<ul class="categories-list">
7+
<li th:each="category: ${categories}">
8+
<a th:text="${category.name}" th:href="|/blog/category/${category.slug}/|"></a>
99
</li>
1010
</ul>
1111
</div>
1212
</body>
13-
</html>
13+
</html>

src/main/resources/templates/fragments/blog/post-preview.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="blog-roll-card">
55
<div class="blog-roll-card-meta">
66
<h2 class="blog-roll-card-header">
7-
<a th:href="|/blog/${post.getSlug()}|">
7+
<a th:href="|/blog/${post.getSlug()}/|">
88
[(${post.title})]
99
</a>
1010
</h2>
@@ -35,7 +35,7 @@ <h2 class="blog-roll-card-header">
3535
<p th:text="${post.summary}"></p>
3636
</div>
3737
<div class="blog-roll-card-footer text-center">
38-
<a th:href="|/blog/${post.slug}|" th:target="_blank" class="main-btn btn-hover">Read More</a>
38+
<a th:href="|/blog/${post.slug}/|" th:target="_blank" class="main-btn btn-hover">Read More</a>
3939
</div>
4040
</div>
4141
</body>

0 commit comments

Comments
 (0)