Skip to content

Commit a837099

Browse files
committed
Add breadcrumbs to JAR, group, and security pages
Google uses breadcrumbs to present search results in a cleaner fashion. This will probably need to be revisited once #482 is decided.
1 parent f448984 commit a837099

File tree

6 files changed

+50
-11
lines changed

6 files changed

+50
-11
lines changed

resources/security.html

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<div class="small-section">
2+
<script type="application/ld+json">
3+
{"@context":"http://schema.org",
4+
"@type":"BreadcrumbList",
5+
"itemListElement":[{"@type":"ListItem",
6+
"position":1,
7+
"item":{"@id":"https://clojars.org/security","name":"Security"}}]}
8+
</script>
29
<h1>Found a security flaw?</h1>
310

411

src/clojars/web/browse.clj

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
[clojars.db :refer [browse-projects count-all-projects
66
count-projects-before]]
77
[hiccup.form :refer [label submit-button text-field submit-button]]
8-
[ring.util.response :refer [redirect]]))
8+
[ring.util.response :refer [redirect]]
9+
[clojars.web.structured-data :as structured-data]))
910

1011
(defn browse-page [db account page per-page]
1112
(let [project-count (count-all-projects db)
1213
total-pages (-> (/ project-count per-page) Math/ceil .intValue)
1314
projects (browse-projects db page per-page)]
1415
(html-doc "All projects" {:account account :description "Browse all of the projects in Clojars"}
1516
[:div.light-article.row
17+
(structured-data/breadcrumbs [{:name "All projects" :url "https://clojars.org/projects"}])
1618
[:h1 "All projects"]
1719
[:div.small-section
1820
[:form.browse-from {:method :get :action "/projects"}

src/clojars/web/common.clj

+6-1
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,13 @@
243243
(str "/" (:jar_name jar))
244244
(str "/" (:group_name jar) "/" (:jar_name jar))))
245245

246+
(defn group-is-name?
247+
"Is the group of the artifact the same as its name?"
248+
[jar]
249+
(= (:group_name jar) (:jar_name jar)))
250+
246251
(defn jar-name [jar]
247-
(if (= (:group_name jar) (:jar_name jar))
252+
(if (group-is-name? jar)
248253
(:jar_name jar)
249254
(str (:group_name jar) "/" (:jar_name jar))))
250255

src/clojars/web/group.clj

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
[clojars.auth :refer [authorized?]]
55
[hiccup.element :refer [unordered-list]]
66
[hiccup.form :refer [text-field submit-button]]
7-
[clojars.web.safe-hiccup :refer [form-to]]))
7+
[clojars.web.safe-hiccup :refer [form-to]]
8+
[clojars.web.structured-data :as structured-data]))
89

910
(defn show-group [db account groupname membernames & errors]
1011
(html-doc (str groupname " group") {:account account :description (format "Clojars projects in the %s group" groupname)}
1112
[:div.small-section.col-md-6.col-lg-6.col-sm-6.col-xs-12
13+
(structured-data/breadcrumbs [{:url (str "https://clojars.org/groups/" groupname)
14+
:name groupname}])
1215
[:h1 (str groupname " group")]
1316
[:h2 "Projects"]
1417
(unordered-list (map jar-link (jars-by-groupname db groupname)))

src/clojars/web/jar.clj

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns clojars.web.jar
22
(:require [clojars.web.common :refer [html-doc jar-link group-link
3-
tag jar-url jar-name user-link
3+
tag jar-url jar-name group-is-name? user-link
44
jar-fork? single-fork-notice
55
simple-date]]
66
hiccup.core
@@ -13,7 +13,8 @@
1313
[clojars.stats :as stats]
1414
[ring.util.codec :refer [url-encode]]
1515
[cheshire.core :as json]
16-
[clojars.web.helpers :as helpers]))
16+
[clojars.web.helpers :as helpers]
17+
[clojars.web.structured-data :as structured-data]))
1718

1819
(defn url-for [jar]
1920
(str (jar-url jar) "/versions/" (:version jar)))
@@ -65,12 +66,21 @@
6566
(:version jar))
6667
(stats/format-stats))]
6768
(html-doc (str (:jar_name jar) " " (:version jar)) {:account account :description (format "%s - %s" (:description jar) (:version jar))
68-
:label1 "Downloads total/this version"
69-
:data1 (format "%s/%s" total-downloads downloads-this-version)
70-
:label2 "Coordinates"
71-
:data2 (format "[%s \"%s\"]" (jar-name jar) (:version jar))}
69+
:label1 "Downloads total/this version"
70+
:data1 (format "%s/%s" total-downloads downloads-this-version)
71+
:label2 "Coordinates"
72+
:data2 (format "[%s \"%s\"]" (jar-name jar) (:version jar))}
7273
(let [pom-map (jar-to-pom-map reporter jar)]
7374
[:div.light-article.row
75+
;; TODO: this could be made more semantic by attaching the metadata to #jar-title, but we're waiting on https://github.com/clojars/clojars-web/issues/482
76+
(structured-data/breadcrumbs (if (group-is-name? jar)
77+
[{:url (str "https://clojars.org/" (jar-name jar))
78+
:name (:jar_name jar)}]
79+
[{:url (str "https://clojars.org/groups/" (:group_name jar))
80+
:name (:group_name jar)}
81+
{:url (str "https://clojars.org/" (jar-name jar)) ;; TODO: Not sure if this is a dirty hack or a stroke of brilliance
82+
:name (:jar_name jar)}]))
83+
7484
(helpers/select-text-script)
7585
[:div#jar-title.col-sm-9.col-lg-9.col-xs-12.col-md-9
7686
[:h1 (jar-link jar)]

src/clojars/web/structured_data.clj

+14-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
[clojure.string :as str]))
77

88
(def common "Common ld-json attributes"
9-
{"@context" "http://schema.org"
10-
"url" "https://clojars.org"})
9+
{"@context" "http://schema.org"})
1110

1211
(defn ld-json
1312
"Takes a map m, converts it to JSON, and puts it inside
@@ -21,6 +20,7 @@
2120
(def website
2221
(ld-json
2322
{"@type" "WebSite"
23+
"url" "https://clojars.org"
2424
"name" "Clojars" ;; https://developers.google.com/structured-data/site-name
2525
"sameAs" ["https://twitter.com/clojars"] ;; https://developers.google.com/structured-data/customize/social-profiles
2626
"potentialAction" ;; https://developers.google.com/structured-data/slsb-overview
@@ -31,6 +31,7 @@
3131
(def organisation
3232
(ld-json
3333
{"@type" "Organization"
34+
"url" "https://clojars.org"
3435
"name" "Clojars"
3536
"logo" "https://clojars.org/images/[email protected]"}))
3637

@@ -72,3 +73,14 @@
7273
(meta-property "og:title" (:title ctx))
7374
(meta-property "og:description" (:description ctx))
7475
(meta-property "og:image" (or (:image-url ctx) "https://clojars.org/images/[email protected]"))))
76+
77+
(defn breadcrumbs [crumbs]
78+
(println crumbs)
79+
(ld-json
80+
{"@type" "BreadcrumbList"
81+
"itemListElement" (into [] (map-indexed (fn [index crumb]
82+
{"@type" "ListItem"
83+
"position" (inc index)
84+
"item" {"@id" (:url crumb)
85+
"name" (:name crumb)}}))
86+
crumbs)}))

0 commit comments

Comments
 (0)