Skip to content

Commit 46a4e36

Browse files
committed
Add a dismissable banner to the header if not on the main branch,
and hide the info in the footer
1 parent 5295ad3 commit 46a4e36

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ WORKDIR /home/opam
1212
ADD rocqproverorg.opam rocqproverorg.opam
1313
RUN opam install . --deps-only
1414

15+
# Git commit and branch information
1516
ARG GIT_COMMIT
1617
RUN echo "Based on commit: $GIT_COMMIT"
1718
ENV GIT_COMMIT=${GIT_COMMIT}
1819
LABEL rocqproverorg=${GIT_COMMIT}
1920

21+
ARG GIT_BRANCH
22+
RUN echo "Based on branch: $GIT_BRANCH"
23+
ENV GIT_BRANCH=${GIT_BRANCH}
24+
LABEL rocqproverorg_branch=${GIT_BRANCH}
25+
2026
# Build project
2127
COPY --chown=opam:opam . .
2228
RUN opam exec -- dune build @install --profile=release
@@ -37,6 +43,11 @@ RUN echo "Based on commit: $GIT_COMMIT"
3743
ENV GIT_COMMIT=${GIT_COMMIT}
3844
LABEL rocqproverorg=${GIT_COMMIT}
3945

46+
ARG GIT_BRANCH
47+
RUN echo "Based on branch: $GIT_BRANCH"
48+
ENV GIT_BRANCH=${GIT_BRANCH}
49+
LABEL rocqproverorg_branch=${GIT_BRANCH}
50+
4051
RUN apk update && apk add --update libev gmp git
4152

4253
RUN chmod -R 755 /var

Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
DOC_PATH=`pwd`/rocq-doc/
33
GIT_HEAD=`git rev-parse HEAD`
44
GIT_COMMIT=${GIT_HEAD}`git diff --quiet HEAD || echo "-dirty"`
5+
GIT_BRANCH=`git branch --show-current`
56

67
.PHONY: all
78
all:
@@ -52,7 +53,7 @@ update-local-doc:
5253

5354
.PHONY: start
5455
start: all update-local-doc ## Run the produced executable
55-
DOC_PATH=${DOC_PATH} GIT_COMMIT=${GIT_COMMIT} opam exec -- dune exec src/rocqproverorg_web/bin/main.exe
56+
DOC_PATH=${DOC_PATH} GIT_COMMIT=${GIT_COMMIT} GIT_BRANCH=${GIT_BRANCH} opam exec -- dune exec src/rocqproverorg_web/bin/main.exe
5657

5758
.PHONY: test
5859
test: ## Run the unit tests
@@ -72,7 +73,7 @@ fmt: ## Format the codebase with ocamlformat
7273

7374
.PHONY: watch
7475
watch: update-local-doc ## Watch for the filesystem and rebuild on every change
75-
DOC_PATH=${DOC_PATH} GIT_COMMIT=${GIT_COMMIT} opam exec -- dune build @run -w --force --no-buffer
76+
DOC_PATH=${DOC_PATH} GIT_COMMIT=${GIT_COMMIT} GIT_BRANCH=${GIT_BRANCH} opam exec -- dune build @run -w --force --no-buffer
7677

7778
.PHONY: utop
7879
utop: ## Run a REPL and link with the project's libraries

compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ services:
55
context: .
66
args:
77
- GIT_COMMIT=${GIT_COMMIT}
8+
- GIT_BRANCH=${GIT_BRANCH}
89
ports:
910
- "127.0.0.1:${LOCAL_PORT}:8080"
1011
volumes:

src/rocqproverorg_frontend/components/footer.eml

+7-3
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,13 @@ let primary_footer () =
173173
<div class="flex w-full md:hidden">
174174
<%s! LightDarkModeSwitch.render %>
175175
</div>
176-
<div class="flex mt-6 space-y-4">
177-
<% let commit = try Sys.getenv "GIT_COMMIT" with Not_found -> failwith "Environment variable GIT_COMMIT is not set" in %>
178-
<%s! link ~href:("https://github.com/coq/rocq-prover.org/commit/" ^ commit) ~name:"GitHub Source" %>
176+
<div class="flex mt-6 space-y-4 hidden">
177+
<% let commit = try Sys.getenv "GIT_COMMIT" with Not_found -> failwith "Environment variable GIT_COMMIT is not set" in
178+
let branch = try Sys.getenv "GIT_BRANCH" with Not_found -> failwith "Environment variable GIT_BRANCH is not set" in %>
179+
<div class="text-base leading-6 text-content dark:text-dark-title">
180+
GitHub <a href="https://github.com/coq/rocq-prover.org/tree/<%s branch %>" class="text-base leading-6 text-content dark:text-dark-title hover:text-primary dark:hover:text-dark-primary">branch</a>
181+
and <a href="https://github.com/coq/rocq-prover.org/commit/<%s commit %>">commit</a>.
182+
</div>
179183
<% ; %>
180184
</div>
181185
</div>

src/rocqproverorg_frontend/components/header.eml

+25-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ let url_of_nav_item = function
2727

2828
let nav_items = [ Learn; Platform; Packages; Community; Consortium; News; Playground ]
2929

30+
let git_branch = try Sys.getenv "GIT_BRANCH" with Not_found -> failwith "Environment variable GIT_BRANCH is not set"
31+
let git_commit = try Sys.getenv "GIT_COMMIT" with Not_found -> failwith "Environment variable GIT_COMMIT is not set"
32+
let git_short_commit = if String.length git_commit > 6 then String.sub git_commit 0 7 else git_commit
33+
3034
let menu_link
3135
~(active: bool)
3236
~href
@@ -51,7 +55,7 @@ let search_dropdown () =
5155
in
5256
<header
5357
class="fixed top-0 z-50 w-full h-20 flex items-center "
54-
x-data="{ open: false }">
58+
x-data="{ open: false }">
5559
<nav class="bg-background container-fluid dark:bg-dark-background_navigation flex gap-5 h-20 header items-center justify-between rounded-b-lg shadow-sm wide xl:gap-8">
5660
<ul class="order-0 space space-x-5 xl:space-x-8 items-center flex text-content font-medium dark:text-title dark:text-opacity-60 dark:font-semibold">
5761
<li style="width:170px">
@@ -102,7 +106,7 @@ in
102106
<nav class="z-50 h-full fixed right-0 top-0 max-w-full w-96 bg-background dark:bg-dark-background shadow-lg" x-show="open" x-cloak
103107
@click.away="open = false" x-transition:enter="transition duration-200 ease-out"
104108
x-transition:enter-start="translate-x-full" x-transition:leave="transition duration-100 ease-in"
105-
x-transition:leave-end="translate-x-full">
109+
x-transition:leave-end="translate-x-full">
106110
<ul class="text-content p-6 font-semibold">
107111
<li class="flex justify-between items-center">
108112
<a href="<%s Url.index %>">
@@ -155,5 +159,24 @@ in
155159
</li>
156160
</ul>
157161
</nav>
162+
<% if git_branch <> "main" then %>
163+
<div id="alert-border-2" class="flex items-center p-4 mb-4 text-red-800 border-t-4 border-red-300 bg-red-50 dark:text-red-400 dark:bg-gray-800 dark:border-red-800" role="alert">
164+
<svg class="flex-shrink-0 w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
165+
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z"/>
166+
</svg>
167+
<div class="ms-3 text-sm font-medium">
168+
You are viewieng the <a class="font-semibold underline hover:no-underline" href="https://github.com/coq/rocq-prover.org/tree/<%s git_branch %>"><%s git_branch %> branch</a> of the website @
169+
<a class="font-semibold underline hover:no-underline" href="https://github.com/coq/rocq-prover.org/commit/<%s git_commit %>"><%s git_short_commit %></a>,
170+
not the <a class="font-semibold underline hover:no-underline" href="https://rocq-prover.org">live version</a>.
171+
</div>
172+
<button type="button" class="ms-auto -mx-1.5 -my-1.5 bg-red-50 text-red-500 rounded-lg focus:ring-2 focus:ring-red-400 p-1.5 hover:bg-red-200 inline-flex items-center justify-center h-8 w-8 dark:bg-gray-800 dark:text-red-400 dark:hover:bg-gray-700" data-dismiss-target="#alert-border-2" aria-label="Close">
173+
<span class="sr-only">Dismiss</span>
174+
<svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
175+
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
176+
</svg>
177+
</button>
178+
</div>
158179
</header>
180+
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/flowbite.min.css" />
181+
<script src="https://unpkg.com/[email protected]/dist/flowbite.js"></script>
159182
<%s! Search.script %>

0 commit comments

Comments
 (0)