diff --git a/.scalafmt.conf b/.scalafmt.conf index 0d96a413f..aa6a4e5db 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = "3.7.9" +version = "3.7.14" runner.dialect = scala213source3 maxColumn = 120 align.preset = some diff --git a/bin/scalafmt b/bin/scalafmt index c8f05afd1..d7a0c4805 100755 Binary files a/bin/scalafmt and b/bin/scalafmt differ diff --git a/modules/core/shared/src/main/scala/scaladex/core/model/HeadMetaProperty.scala b/modules/core/shared/src/main/scala/scaladex/core/model/HeadMetaProperty.scala new file mode 100644 index 000000000..2f947d828 --- /dev/null +++ b/modules/core/shared/src/main/scala/scaladex/core/model/HeadMetaProperty.scala @@ -0,0 +1,9 @@ +package scaladex.core.model + +/** + * A meta tag in head that uses property attribute. + * + * @param property The property attribute + * @param content The content attribute + */ +case class HeadMetaProperty(property: String, content: String) diff --git a/modules/core/shared/src/main/scala/scaladex/core/model/OGP.scala b/modules/core/shared/src/main/scala/scaladex/core/model/OGP.scala new file mode 100644 index 000000000..c7cb9e427 --- /dev/null +++ b/modules/core/shared/src/main/scala/scaladex/core/model/OGP.scala @@ -0,0 +1,30 @@ +package scaladex.core.model + +/** + * Open Graph Protocol, see https://ogp.me/ + * + * @param title + * @param url + * @param description + * @param image + * @param imageAlt + */ +case class OGP( + title: String, + url: Url, + description: String, + image: Option[Url] = None, + imageAlt: Option[String] = None +) { + val `type`: String = "article" + val siteName: String = "Scaladex" + def toHeadMetaProperty: Seq[HeadMetaProperty] = Seq( + HeadMetaProperty(property = "og:title", content = title), + HeadMetaProperty(property = "og:url", content = url.target), + HeadMetaProperty(property = "og:type", content = `type`), + HeadMetaProperty(property = "og:description", content = description), + HeadMetaProperty(property = "og:site_name", content = siteName) + ) ++ image.map(c => HeadMetaProperty(property = "og:image", content = c.target)) ++ imageAlt.map(c => + HeadMetaProperty(property = "og:image:alt", c) + ) +} diff --git a/modules/core/shared/src/main/scala/scaladex/core/model/Project.scala b/modules/core/shared/src/main/scala/scaladex/core/model/Project.scala index 1c79a0e9c..70a58a141 100644 --- a/modules/core/shared/src/main/scala/scaladex/core/model/Project.scala +++ b/modules/core/shared/src/main/scala/scaladex/core/model/Project.scala @@ -28,6 +28,16 @@ case class Project( githubInfo.flatMap(_.logo) ) + /** + * This is used in embedding to another website to render the card of a scaladex project link. + */ + def ogp: OGP = OGP( + title = s"Scaladex - ${organization.toString()} / ${repository.toString()}", + url = Url(s"https://index.scala-lang.org/${organization.toString()}/${repository.toString()}"), + description = githubInfo.flatMap(_.description).getOrElse(""), + image = githubInfo.flatMap(_.logo).orElse(Some(Url("https://index.scala-lang.org/assets/img/scaladex-brand.svg"))) + ) + def scaladoc(artifact: Artifact): Option[DocumentationLink] = settings.customScalaDoc .map(DocumentationPattern("Scaladoc", _).eval(artifact)) diff --git a/modules/template/src/main/twirl/scaladex/view/main.scala.html b/modules/template/src/main/twirl/scaladex/view/main.scala.html index 6f93128d8..3972dd926 100644 --- a/modules/template/src/main/twirl/scaladex/view/main.scala.html +++ b/modules/template/src/main/twirl/scaladex/view/main.scala.html @@ -1,6 +1,7 @@ @import scaladex.core.model.search.SearchParams @import scaladex.core.model.UserState @import scaladex.core.model.HeadMeta +@import scaladex.core.model.HeadMetaProperty @import scaladex.core.model.Env @( @@ -10,6 +11,7 @@ showSearch: Boolean = true, params: SearchParams = SearchParams(), you: Boolean = false, extraMeta: Seq[HeadMeta] = Seq.empty, + extraMetaProperty: Seq[HeadMetaProperty] = Seq.empty, totalProjects: Option[Long] = None, totalArtifacts: Option[Long] = None )(content: Html) @@ -47,6 +49,9 @@ @for(meta <- extraMeta) { } + @for(meta <- extraMetaProperty) { + + }
diff --git a/modules/template/src/main/twirl/scaladex/view/project/badges.scala.html b/modules/template/src/main/twirl/scaladex/view/project/badges.scala.html index eb2607d97..bff4a901f 100644 --- a/modules/template/src/main/twirl/scaladex/view/project/badges.scala.html +++ b/modules/template/src/main/twirl/scaladex/view/project/badges.scala.html @@ -15,7 +15,7 @@ header: ProjectHeader, artifact: Artifact ) -@main(env, title = project.repository.value, user, extraMeta = project.twitterCard.toHeadMeta) { +@main(env, title = project.repository.value, user, extraMeta = project.twitterCard.toHeadMeta, extraMetaProperty = project.ogp.toHeadMetaProperty) {