From cc7b7f91dfb455c472cbcab9cd4a6cf6200cff9b Mon Sep 17 00:00:00 2001 From: Ryan Peters Date: Wed, 27 Jan 2021 14:57:31 -0600 Subject: [PATCH 1/5] Add config for call-to-action button target --- microsite/docs/docs/settings.md | 2 ++ src/main/scala/microsites/MicrositeKeys.scala | 7 ++++++- .../scala/microsites/MicrositesPlugin.scala | 1 + .../microsites/layouts/FeaturesLayout.scala | 8 +------- .../scala/microsites/layouts/HomeLayout.scala | 16 ++------------- .../scala/microsites/layouts/Layout.scala | 20 +++++++++++++++++++ src/main/scala/microsites/microsites.scala | 3 ++- 7 files changed, 34 insertions(+), 23 deletions(-) diff --git a/microsite/docs/docs/settings.md b/microsite/docs/docs/settings.md index 081229fc..0e4bf77d 100644 --- a/microsite/docs/docs/settings.md +++ b/microsite/docs/docs/settings.md @@ -290,6 +290,8 @@ Each file (the map key) can be related to a specific configuration through the ` micrositePluginsDirectory := (resourceDirectory in Compile).value / "site" / "plugins" ``` +- `micrositeHomeButtonTarget`: Where the large "call-to-action button" on your home page should take users. By default is set to `repo` for your project repository. Can be set to `docs` to take users to the project documentation page, if configured. + - `micrositeSearchEnabled`: Whether or not the search bar functionality is enabled for your microsite. Enabled by default. To disable, set to `false`. - `micrositeTheme`: You can choose two different themes to generate your microsite. By default it will display the `light` theme but you have the option of choosing the classic `pattern` theme. diff --git a/src/main/scala/microsites/MicrositeKeys.scala b/src/main/scala/microsites/MicrositeKeys.scala index 40b1583b..00af515d 100644 --- a/src/main/scala/microsites/MicrositeKeys.scala +++ b/src/main/scala/microsites/MicrositeKeys.scala @@ -214,6 +214,10 @@ trait MicrositeKeys { val micrositeSearchEnabled: SettingKey[Boolean] = settingKey[Boolean]( "Adds a search bar and search features to your website using Lunr.js. Default is 'true'" ) + + val micrositeHomeButtonTarget: SettingKey[String] = settingKey[String]( + "Determines where the large, home-page call-to-action button links to. Default is 'repo' which links to the project open source repository. Can also be set to `docs` to link to your main documentation page." + ) } object MicrositeKeys extends MicrositeKeys @@ -362,7 +366,8 @@ trait MicrositeAutoImportSettings extends MicrositeKeys { micrositeUrl = micrositeUrl.value, micrositeBaseUrl = micrositeBaseUrl.value, micrositeDocumentationUrl = micrositeDocumentationUrl.value, - micrositeDocumentationLabelDescription = micrositeDocumentationLabelDescription.value + micrositeDocumentationLabelDescription = micrositeDocumentationLabelDescription.value, + micrositeHomeButtonTarget = "repo" ), gitSettings = MicrositeGitSettings( githubOwner = micrositeGitHostingService.value match { diff --git a/src/main/scala/microsites/MicrositesPlugin.scala b/src/main/scala/microsites/MicrositesPlugin.scala index a5d71c75..e06924ea 100644 --- a/src/main/scala/microsites/MicrositesPlugin.scala +++ b/src/main/scala/microsites/MicrositesPlugin.scala @@ -123,6 +123,7 @@ object MicrositesPlugin extends AutoPlugin { micrositeEditButton := None, micrositeGithubLinks := true, micrositeSearchEnabled := true, + micrositeHomeButtonTarget := "repo", includeFilter in makeSite := "*.html" | "*.css" | "*.png" | "*.jpg" | "*.jpeg" | "*.gif" | "*.js" | "*.swf" | "*.md" | "*.webm" | "*.ico" | "CNAME" | "*.yml" | "*.svg" | "*.json", includeFilter in Jekyll := (includeFilter in makeSite).value || "LICENSE", commands ++= Seq(publishMicrositeCommand), diff --git a/src/main/scala/microsites/layouts/FeaturesLayout.scala b/src/main/scala/microsites/layouts/FeaturesLayout.scala index 83605ee0..448cbb2a 100644 --- a/src/main/scala/microsites/layouts/FeaturesLayout.scala +++ b/src/main/scala/microsites/layouts/FeaturesLayout.scala @@ -50,13 +50,7 @@ class FeaturesLayout(config: MicrositeSettings) extends Layout(config) { cls := "features-header-description", h1(cls := "masthead-title", config.identity.name), p(cls := "masthead-description", config.identity.description), - a( - href := config.gitSiteUrl, - target := "_blank", - rel := "noopener noreferrer", - cls := "masthead-button", - s"View on ${config.gitSettings.gitHostingService.name}" - ) + ctaButton("masthead-button") ), div(cls := "features-image") ) diff --git a/src/main/scala/microsites/layouts/HomeLayout.scala b/src/main/scala/microsites/layouts/HomeLayout.scala index a980538e..3bcb35ff 100644 --- a/src/main/scala/microsites/layouts/HomeLayout.scala +++ b/src/main/scala/microsites/layouts/HomeLayout.scala @@ -71,13 +71,7 @@ class HomeLayout(config: MicrositeSettings) extends Layout(config) { h2(), p( cls := "text-center", - a( - href := config.gitSiteUrl, - target := "_blank", - rel := "noopener noreferrer", - cls := "btn btn-outline-inverse", - s"View on ${config.gitSettings.gitHostingService.name}" - ) + ctaButton("btn btn-outline-inverse") ) ) ), @@ -91,13 +85,7 @@ class HomeLayout(config: MicrositeSettings) extends Layout(config) { div( cls := "container text-center", h1(cls := "masthead-description", config.identity.description), - a( - href := config.gitSiteUrl, - target := "_blank", - rel := "noopener noreferrer", - cls := "masthead-button", - s"View on ${config.gitSettings.gitHostingService.name}" - ) + ctaButton("masthead-button") ) ), "{% if page.position != null %}", diff --git a/src/main/scala/microsites/layouts/Layout.scala b/src/main/scala/microsites/layouts/Layout.scala index 1ce5fd6f..9f142d4b 100644 --- a/src/main/scala/microsites/layouts/Layout.scala +++ b/src/main/scala/microsites/layouts/Layout.scala @@ -557,4 +557,24 @@ abstract class Layout(config: MicrositeSettings) { private[this] def validFile(extension: String)(file: File): Boolean = file.getName.endsWith(s".$extension") + + def ctaButton(linkClass: String): TypedTag[String] = { + if (config.urlSettings.micrositeHomeButtonTarget == "repo") { + a( + href := config.gitSiteUrl, + target := "_blank", + rel := "noopener noreferrer", + cls := linkClass, + s"View on ${config.gitSettings.gitHostingService.name}" + ) + } else { + a( + href := s"/${config.urlSettings.micrositeBaseUrl}${config.urlSettings.micrositeDocumentationUrl}", + target := "_blank", + rel := "noopener noreferrer", + cls := linkClass, + s"View Docs" + ) + } + } } diff --git a/src/main/scala/microsites/microsites.scala b/src/main/scala/microsites/microsites.scala index 48b7ea8d..f99efa85 100644 --- a/src/main/scala/microsites/microsites.scala +++ b/src/main/scala/microsites/microsites.scala @@ -58,7 +58,8 @@ case class MicrositeUrlSettings( micrositeUrl: String, micrositeBaseUrl: String, micrositeDocumentationUrl: String, - micrositeDocumentationLabelDescription: String + micrositeDocumentationLabelDescription: String, + micrositeHomeButtonTarget: String ) case class MicrositeFavicon(filename: String, sizeDescription: String) From 273cc6efb2ae7dbec3182f6320af5d4c2e0cf8d9 Mon Sep 17 00:00:00 2001 From: Ryan Peters Date: Wed, 27 Jan 2021 15:26:45 -0600 Subject: [PATCH 2/5] Fix home button key not being used --- src/main/scala/microsites/MicrositeKeys.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/microsites/MicrositeKeys.scala b/src/main/scala/microsites/MicrositeKeys.scala index 00af515d..a0008b41 100644 --- a/src/main/scala/microsites/MicrositeKeys.scala +++ b/src/main/scala/microsites/MicrositeKeys.scala @@ -367,7 +367,7 @@ trait MicrositeAutoImportSettings extends MicrositeKeys { micrositeBaseUrl = micrositeBaseUrl.value, micrositeDocumentationUrl = micrositeDocumentationUrl.value, micrositeDocumentationLabelDescription = micrositeDocumentationLabelDescription.value, - micrositeHomeButtonTarget = "repo" + micrositeHomeButtonTarget = micrositeHomeButtonTarget.value ), gitSettings = MicrositeGitSettings( githubOwner = micrositeGitHostingService.value match { From 42ed3e90b1dad242fdd04a9a745e10e39085301e Mon Sep 17 00:00:00 2001 From: Ryan Peters Date: Wed, 27 Jan 2021 15:46:51 -0600 Subject: [PATCH 3/5] Fix Arbitraries for new home button config --- src/test/scala/microsites/util/Arbitraries.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/scala/microsites/util/Arbitraries.scala b/src/test/scala/microsites/util/Arbitraries.scala index 1934b98f..4cf4d12b 100644 --- a/src/test/scala/microsites/util/Arbitraries.scala +++ b/src/test/scala/microsites/util/Arbitraries.scala @@ -22,6 +22,7 @@ import microsites.MicrositeKeys._ import microsites._ import org.scalacheck.Arbitrary import org.scalacheck.Gen._ +import org.scalacheck.Gen trait Arbitraries { @@ -143,6 +144,7 @@ trait Arbitraries { micrositeEditButton ← micrositeEditButtonArbitrary.arbitrary micrositeVersionList ← Arbitrary.arbitrary[Seq[String]] micrositeSearchBar <- Arbitrary.arbitrary[Boolean] + micrositeHomeButtonTarget <- Gen.oneOf("docs", "repo") } yield MicrositeSettings( MicrositeIdentitySettings( name, @@ -184,7 +186,8 @@ trait Arbitraries { micrositeUrl, micrositeBaseUrl, micrositeDocumentationUrl, - micrositeDocumentationLabelDescription + micrositeDocumentationLabelDescription, + micrositeHomeButtonTarget ), MicrositeGitSettings( githubOwner, From b15dcf7787aac83284e111115b85eafacd3df27c Mon Sep 17 00:00:00 2001 From: Ryan Peters Date: Wed, 27 Jan 2021 15:48:54 -0600 Subject: [PATCH 4/5] Add missing / from docs href --- src/main/scala/microsites/layouts/Layout.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/microsites/layouts/Layout.scala b/src/main/scala/microsites/layouts/Layout.scala index 9f142d4b..026517c8 100644 --- a/src/main/scala/microsites/layouts/Layout.scala +++ b/src/main/scala/microsites/layouts/Layout.scala @@ -569,7 +569,7 @@ abstract class Layout(config: MicrositeSettings) { ) } else { a( - href := s"/${config.urlSettings.micrositeBaseUrl}${config.urlSettings.micrositeDocumentationUrl}", + href := s"/${config.urlSettings.micrositeBaseUrl}/${config.urlSettings.micrositeDocumentationUrl}", target := "_blank", rel := "noopener noreferrer", cls := linkClass, From 6ccc5fa69c323fbee59aab3f9636c93191db89ba Mon Sep 17 00:00:00 2001 From: Ryan Peters Date: Wed, 27 Jan 2021 17:02:56 -0600 Subject: [PATCH 5/5] Center-align text in home page button --- src/main/resources/_sass/light-style/_features.scss | 1 + src/main/resources/_sass/light-style/_masthead.scss | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/resources/_sass/light-style/_features.scss b/src/main/resources/_sass/light-style/_features.scss index b25fb8ef..61d1d5b7 100644 --- a/src/main/resources/_sass/light-style/_features.scss +++ b/src/main/resources/_sass/light-style/_features.scss @@ -37,6 +37,7 @@ margin: 0 0 10px 0; } .masthead-button { + text-align: center; width: 106px; margin-top: $base-point-grid * 2; } diff --git a/src/main/resources/_sass/light-style/_masthead.scss b/src/main/resources/_sass/light-style/_masthead.scss index c7349a80..33132835 100644 --- a/src/main/resources/_sass/light-style/_masthead.scss +++ b/src/main/resources/_sass/light-style/_masthead.scss @@ -28,6 +28,7 @@ } .masthead-button { + text-align: center; color: $white-color; padding: 11px ($base-point-grid * 5); border: 2px solid $white-color;