diff --git a/README.md b/README.md index e17b3d6..6c44fe1 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ To fetch your ButterCMS content, add your API token as an environment variable. Build the project with the following command -`$ mvn install -DskipTests` +`$ mvn install` ### 4. Run the project @@ -45,6 +45,12 @@ To view the app in the browser, you'll need to run the local development server: `$ mvn spring-boot:run` +Alternatively, you can run it directly via the `java` command + +`$ java -jar target/spring-starter-buttercms-*.jar` + +where the file name `spring-starter-buttercms` will be appended by the value of the version tag `` in [pom.xml](pom.xml) + Congratulations! Your starter project is now live. To view your project, point your browser to [http://localhost:8080](http://localhost:8080). @@ -61,4 +67,4 @@ and institute a full content workflow connected to your ButterCMS account. Smoot By default, your starter project is set up to allow previewing of draft changes saved in your ButterCMS.com account. To disable this functionality, set the -following value in your .env file: JAVA_BUTTER_CMS_PREVIEW=false +following value in your .env file: `JAVA_BUTTER_CMS_PREVIEW=false` diff --git a/src/main/java/com/buttercms/springstarterbuttercms/controller/BlogController.java b/src/main/java/com/buttercms/springstarterbuttercms/controller/BlogController.java index 2d0bd45..c3dff86 100644 --- a/src/main/java/com/buttercms/springstarterbuttercms/controller/BlogController.java +++ b/src/main/java/com/buttercms/springstarterbuttercms/controller/BlogController.java @@ -4,10 +4,7 @@ import com.buttercms.springstarterbuttercms.service.BlogService; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; @Controller public class BlogController { @@ -67,8 +64,8 @@ public String blogByTag(@PathVariable String tagSlug, Model model) { return "blogs"; } - @PostMapping("/blog/search") - public String search(@RequestParam String searchTerm, Model model) { + @GetMapping(value = "/blog/search") + public String search(@RequestParam(name = "q", required = false, defaultValue = "") String searchTerm, Model model) { BlogsDto blogsDto = blogService.searchBlogs(searchTerm); model.addAttribute("posts", blogsDto.getPosts()); model.addAttribute("categories", blogsDto.getCategories()); diff --git a/src/main/java/com/buttercms/springstarterbuttercms/controller/IndexController.java b/src/main/java/com/buttercms/springstarterbuttercms/controller/IndexController.java index 5367be5..8dd097a 100644 --- a/src/main/java/com/buttercms/springstarterbuttercms/controller/IndexController.java +++ b/src/main/java/com/buttercms/springstarterbuttercms/controller/IndexController.java @@ -1,6 +1,8 @@ package com.buttercms.springstarterbuttercms.controller; import com.buttercms.springstarterbuttercms.controller.dto.LandingPageDto; +import com.buttercms.springstarterbuttercms.model.landingpage.Field; +import com.buttercms.springstarterbuttercms.model.landingpage.Fields; import com.buttercms.springstarterbuttercms.model.landingpage.Section; import com.buttercms.springstarterbuttercms.model.landingpage.Seo; import com.buttercms.springstarterbuttercms.service.PageCollectionService; @@ -22,13 +24,12 @@ public IndexController(PageCollectionService pageCollectionService) { @GetMapping(value = {"/","/landing-page/{slug}"}) public String index(@PathVariable(required = false) String slug, Model model) { - LandingPageDto landingPage = pageCollectionService.getLandingPage(); + LandingPageDto landingPage = pageCollectionService.getLandingPage("landing-page", slug); Seo seo = landingPage.getFields().getSeo(); - List
sections = landingPage.extractSections(landingPage.getFields()); model.addAttribute("posts", landingPage.getPosts()); model.addAttribute("seoTitle", seo.getTitle()); model.addAttribute("seoDescription", seo.getDescription()); - model.addAttribute("sections", sections); + model.addAttribute("fields", landingPage.getFields().getFields()); return "index"; } } diff --git a/src/main/java/com/buttercms/springstarterbuttercms/controller/dto/ConstDtoValues.java b/src/main/java/com/buttercms/springstarterbuttercms/controller/dto/ConstDtoValues.java index 96f46a2..5041d06 100644 --- a/src/main/java/com/buttercms/springstarterbuttercms/controller/dto/ConstDtoValues.java +++ b/src/main/java/com/buttercms/springstarterbuttercms/controller/dto/ConstDtoValues.java @@ -4,7 +4,7 @@ public class ConstDtoValues { public static String BLOG_SEO_TITLE = "Sample Blog - All Posts"; public static String BLOG_SEO_DESCRIPTION = "Sample blog powered by ButterCMS, showing all posts."; public static String BLOG_CATEGORY_SEO_TITLE = "Sample Blog - category: "; - public static String BLOG_CATEGORY_SEO_DESCRIPTION = "Sample Blog - category: "; + public static String BLOG_CATEGORY_SEO_DESCRIPTION = "Sample blog powered by ButterCMS, showing category: "; public static String BLOG_TAG_SEO_TITLE = "Sample Blog - tag: "; public static String BLOG_TAG_SEO_DESCRIPTION = "Sample blog powered by ButterCMS, showing tag: "; public static String BLOG_SEARCH_SEO_TITLE = "Sample Blog - search results for "; diff --git a/src/main/java/com/buttercms/springstarterbuttercms/model/landingpage/Field.java b/src/main/java/com/buttercms/springstarterbuttercms/model/landingpage/Field.java index 1cb6350..3794909 100644 --- a/src/main/java/com/buttercms/springstarterbuttercms/model/landingpage/Field.java +++ b/src/main/java/com/buttercms/springstarterbuttercms/model/landingpage/Field.java @@ -1,10 +1,26 @@ package com.buttercms.springstarterbuttercms.model.landingpage; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; public class Field { private String type; @JsonProperty("fields") + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXTERNAL_PROPERTY, + property = "type", + visible = true + ) + @JsonSubTypes({ + @JsonSubTypes.Type(value = BasicSection.class, name = "hero"), + @JsonSubTypes.Type(value = ImageSection.class, name = "two_column_with_image"), + @JsonSubTypes.Type(value = FeaturesSection.class, name = "features"), + @JsonSubTypes.Type(value = TestimonialsSection.class, name = "testimonials") + }) private Section section; public String getType() { diff --git a/src/main/java/com/buttercms/springstarterbuttercms/model/landingpage/Section.java b/src/main/java/com/buttercms/springstarterbuttercms/model/landingpage/Section.java index 6f3c016..674c58f 100644 --- a/src/main/java/com/buttercms/springstarterbuttercms/model/landingpage/Section.java +++ b/src/main/java/com/buttercms/springstarterbuttercms/model/landingpage/Section.java @@ -1,24 +1,8 @@ package com.buttercms.springstarterbuttercms.model.landingpage; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonTypeInfo( - use = JsonTypeInfo.Id.NAME, - include = JsonTypeInfo.As.EXISTING_PROPERTY, - property = "scroll_anchor_id", - visible = true -) -@JsonSubTypes({ - @JsonSubTypes.Type(value = BasicSection.class, name = "home"), - @JsonSubTypes.Type(value = ImageSection.class, name = "about"), - @JsonSubTypes.Type(value = ImageSection.class, name = "tryit"), - @JsonSubTypes.Type(value = FeaturesSection.class, name = "features"), - @JsonSubTypes.Type(value = TestimonialsSection.class, name = "testimonials") -}) + public abstract class Section { @JsonProperty("scroll_anchor_id") private String scrollAnchorId; @@ -37,4 +21,4 @@ public String getScrollAnchorId() { public void setScrollAnchorId(String scrollAnchorId) { this.scrollAnchorId = scrollAnchorId; } -} \ No newline at end of file +} diff --git a/src/main/java/com/buttercms/springstarterbuttercms/service/PageCollectionService.java b/src/main/java/com/buttercms/springstarterbuttercms/service/PageCollectionService.java index 372ce3f..20b4996 100644 --- a/src/main/java/com/buttercms/springstarterbuttercms/service/PageCollectionService.java +++ b/src/main/java/com/buttercms/springstarterbuttercms/service/PageCollectionService.java @@ -16,19 +16,22 @@ public class PageCollectionService { private final IButterCMSClient butterCMSClient; + private final static String DEFAULT_LANDING_PAGE = "landing-page-with-components"; + public PageCollectionService(IButterCMSClient butterCMSClient) { this.butterCMSClient = butterCMSClient; } - public LandingPageDto getLandingPage() { + public LandingPageDto getLandingPage(String pageType, String slug) { + slug = slug == null ? DEFAULT_LANDING_PAGE : slug; Map queryParams = new HashMap() {{ put("page", "1"); put("page_size", "2"); }}; List posts = butterCMSClient.getPosts(queryParams).getData(); Fields landingPage = butterCMSClient.getPage( - "*", - "landing-page-with-components", + pageType, + slug, new HashMap<>(), Fields.class ).getData().getFields(); diff --git a/src/main/resources/static/js/section-menu.js b/src/main/resources/static/js/section-menu.js index ed50e69..45d7478 100644 --- a/src/main/resources/static/js/section-menu.js +++ b/src/main/resources/static/js/section-menu.js @@ -9,7 +9,7 @@ var val = currLink.getAttribute('href').replaceAll("/", ""); var refElement = document.querySelector(val); var scrollTopMinus = scrollPos + 73; - if (refElement.offsetTop <= scrollTopMinus && (refElement.offsetTop + refElement.offsetHeight > scrollTopMinus)) { + if (refElement && refElement.offsetTop <= scrollTopMinus && (refElement.offsetTop + refElement.offsetHeight > scrollTopMinus)) { document.querySelector('.page-scroll').classList.remove('active'); currLink.classList.add('active'); } else { diff --git a/src/main/resources/templates/fragments/blog/categories.html b/src/main/resources/templates/fragments/blog/categories.html index b7d206a..3c8d85f 100644 --- a/src/main/resources/templates/fragments/blog/categories.html +++ b/src/main/resources/templates/fragments/blog/categories.html @@ -3,11 +3,11 @@
Categories
-
    -
  • - +
      +
    • +
- \ No newline at end of file + diff --git a/src/main/resources/templates/fragments/blog/post-preview.html b/src/main/resources/templates/fragments/blog/post-preview.html index eae13c4..bf62f1f 100644 --- a/src/main/resources/templates/fragments/blog/post-preview.html +++ b/src/main/resources/templates/fragments/blog/post-preview.html @@ -4,7 +4,7 @@ diff --git a/src/main/resources/templates/fragments/blog/search.html b/src/main/resources/templates/fragments/blog/search.html index 40e7d93..e2c452c 100644 --- a/src/main/resources/templates/fragments/blog/search.html +++ b/src/main/resources/templates/fragments/blog/search.html @@ -4,11 +4,11 @@ - \ No newline at end of file + diff --git a/src/main/resources/templates/fragments/blog/tag.html b/src/main/resources/templates/fragments/blog/tag.html index 23ae74b..483e496 100644 --- a/src/main/resources/templates/fragments/blog/tag.html +++ b/src/main/resources/templates/fragments/blog/tag.html @@ -1,9 +1,9 @@ - + [(${tag.name})] - \ No newline at end of file + diff --git a/src/main/resources/templates/fragments/common-elements/header.html b/src/main/resources/templates/fragments/common-elements/header.html index b5b979d..e2ac954 100644 --- a/src/main/resources/templates/fragments/common-elements/header.html +++ b/src/main/resources/templates/fragments/common-elements/header.html @@ -34,4 +34,4 @@ - \ No newline at end of file + diff --git a/src/main/resources/templates/fragments/landing-page/about.html b/src/main/resources/templates/fragments/landing-page/about.html deleted file mode 100644 index db4ab0f..0000000 --- a/src/main/resources/templates/fragments/landing-page/about.html +++ /dev/null @@ -1,28 +0,0 @@ - - - -
-
-
-
-
-
- -
-
-
-
-
-

-

[(${section.subHeadline})]

- -
-
-
-
-
-
-
- - diff --git a/src/main/resources/templates/fragments/landing-page/features.html b/src/main/resources/templates/fragments/landing-page/features.html index df0a010..4a33065 100644 --- a/src/main/resources/templates/fragments/landing-page/features.html +++ b/src/main/resources/templates/fragments/landing-page/features.html @@ -1,8 +1,8 @@ -
-
+
+
diff --git a/src/main/resources/templates/fragments/landing-page/home.html b/src/main/resources/templates/fragments/landing-page/home.html index a407a86..7dd47b2 100644 --- a/src/main/resources/templates/fragments/landing-page/home.html +++ b/src/main/resources/templates/fragments/landing-page/home.html @@ -1,8 +1,8 @@ -
-
+
+
diff --git a/src/main/resources/templates/fragments/landing-page/latest-blogs.html b/src/main/resources/templates/fragments/landing-page/latest-blogs.html index 7afa417..cc3434e 100644 --- a/src/main/resources/templates/fragments/landing-page/latest-blogs.html +++ b/src/main/resources/templates/fragments/landing-page/latest-blogs.html @@ -34,14 +34,14 @@

Latest Blog Posts

diff --git a/src/main/resources/templates/fragments/landing-page/testimonials.html b/src/main/resources/templates/fragments/landing-page/testimonials.html index 3cf54e0..db7df34 100644 --- a/src/main/resources/templates/fragments/landing-page/testimonials.html +++ b/src/main/resources/templates/fragments/landing-page/testimonials.html @@ -1,8 +1,8 @@ -
-
+
+
diff --git a/src/main/resources/templates/fragments/landing-page/try-it.html b/src/main/resources/templates/fragments/landing-page/try-it.html index 9b2d6ef..fb78fb2 100644 --- a/src/main/resources/templates/fragments/landing-page/try-it.html +++ b/src/main/resources/templates/fragments/landing-page/try-it.html @@ -1,8 +1,8 @@ -
-
+
+
diff --git a/src/main/resources/templates/fragments/landing-page/two_column_with_image.html b/src/main/resources/templates/fragments/landing-page/two_column_with_image.html new file mode 100644 index 0000000..1e19d45 --- /dev/null +++ b/src/main/resources/templates/fragments/landing-page/two_column_with_image.html @@ -0,0 +1,50 @@ + + + +
+
+
+
+
+
+
+

+

[(${section.subHeadline})]

+ +
+
+
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+
+
+

+

[(${section.subHeadline})]

+ +
+
+
+
+
+
+
+ + diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 9cda8e3..7d90ee5 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -58,12 +58,11 @@
-
-
-
-
-
-
+
+
+
+
+