WIP: New Flow website built with Nanoc and Mage #1

Draft
dananglin wants to merge 9 commits from new-site into main
33 changed files with 934 additions and 304 deletions

3
.gitattributes vendored
View file

@ -1,2 +1 @@
web/static/gpg/public.asc filter=lfs diff=lfs merge=lfs -text
web/static/img/favicon.ico filter=lfs diff=lfs merge=lfs -text
flow/content/favicon.ico filter=lfs diff=lfs merge=lfs -text

7
.gitignore vendored
View file

@ -1 +1,6 @@
/landing
/flow/output/
/flow/tmp/
/flow/crash.log
/flow/content/projects/
!/flow/content/projects/index.asciidoc
/website

View file

@ -1,7 +1,35 @@
# syntax=docker/dockerfile:1
# Build the nanoc site
FROM ruby:3.3 AS site-builder
ARG ENVIRONMENT
COPY flow/ /workspace
WORKDIR /workspace
RUN bundle install \
&& bundle exec nanoc compile --env=${ENVIRONMENT}
# Build the web server
FROM golang:1.21-alpine AS server-builder
COPY go.mod /workspace/go.mod
COPY main.go /workspace/main.go
COPY --from=site-builder /workspace/output/ /workspace/flow/output/
WORKDIR /workspace
RUN go build -ldflags="-s -w" -a -v -o website .
# Create the final image
FROM scratch
ADD landing /landing
COPY --from=server-builder /workspace/website /website
USER 65534
ENTRYPOINT ["/landing"]
ENTRYPOINT ["/website"]
HEALTHCHECK NONE

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2023 Dan Anglin
Copyright (c) 2024 Dan Anglin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

12
flow/Gemfile Normal file
View file

@ -0,0 +1,12 @@
# frozen_string_literal: true
source 'https://rubygems.org'
gem 'asciidoctor', '= 2.0.20'
gem 'nanoc', '= 4.12.19'
group 'nanoc' do
gem 'base64', '= 0.2.0'
gem 'nanoc-live', '= 1.0.0'
gem 'webrick', '= 1.8.1'
end

113
flow/Gemfile.lock Normal file
View file

@ -0,0 +1,113 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
adsf (1.4.6)
rack (>= 1.0.0, < 3.0.0)
adsf-live (1.5.0)
adsf (~> 1.3)
em-websocket (~> 0.5)
eventmachine (~> 1.2)
listen (~> 3.0)
rack-livereload (~> 0.3)
asciidoctor (2.0.20)
base64 (0.2.0)
colored (1.2)
concurrent-ruby (1.2.3)
cri (2.15.11)
ddmetrics (1.1.0)
ddplugin (1.0.3)
diff-lcs (1.5.1)
em-websocket (0.5.3)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0)
eventmachine (1.2.7)
ffi (1.16.3)
http_parser.rb (0.8.0)
immutable-ruby (0.1.0)
concurrent-ruby (~> 1.1)
sorted_set (~> 1.0)
json_schema (0.21.0)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
memo_wise (1.8.0)
nanoc (4.12.19)
addressable (~> 2.5)
colored (~> 1.2)
nanoc-checking (~> 1.0, >= 1.0.2)
nanoc-cli (= 4.12.19)
nanoc-core (= 4.12.19)
nanoc-deploying (~> 1.0)
parallel (~> 1.12)
tty-command (~> 0.8)
tty-which (~> 0.4)
nanoc-checking (1.0.2)
nanoc-cli (~> 4.12, >= 4.12.4)
nanoc-core (~> 4.12, >= 4.12.4)
nanoc-cli (4.12.19)
cri (~> 2.15)
diff-lcs (~> 1.3)
nanoc-core (= 4.12.19)
zeitwerk (~> 2.1)
nanoc-core (4.12.19)
concurrent-ruby (~> 1.1)
ddmetrics (~> 1.0)
ddplugin (~> 1.0)
immutable-ruby (~> 0.1)
json_schema (~> 0.19)
memo_wise (~> 1.5)
psych (>= 4.0, < 6.0)
slow_enumerator_tools (~> 1.0)
tty-platform (~> 0.2)
zeitwerk (~> 2.1)
nanoc-deploying (1.0.2)
nanoc-checking (~> 1.0)
nanoc-cli (~> 4.11, >= 4.11.15)
nanoc-core (~> 4.11, >= 4.11.15)
nanoc-live (1.0.0)
adsf-live (~> 1.4)
listen (~> 3.0)
nanoc-cli (~> 4.11, >= 4.11.14)
nanoc-core (~> 4.11, >= 4.11.14)
parallel (1.24.0)
pastel (0.8.0)
tty-color (~> 0.5)
psych (5.1.2)
stringio
public_suffix (5.0.4)
rack (2.2.8)
rack-livereload (0.5.2)
rack (< 3)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rbtree (0.4.6)
set (1.1.0)
slow_enumerator_tools (1.1.0)
sorted_set (1.0.3)
rbtree
set (~> 1.0)
stringio (3.1.0)
tty-color (0.6.0)
tty-command (0.10.1)
pastel (~> 0.8)
tty-platform (0.3.0)
tty-which (0.5.0)
webrick (1.8.1)
zeitwerk (2.6.12)
PLATFORMS
ruby
x86_64-linux
DEPENDENCIES
asciidoctor (= 2.0.20)
base64 (= 0.2.0)
nanoc (= 4.12.19)
nanoc-live (= 1.0.0)
webrick (= 1.8.1)
BUNDLED WITH
2.5.5

18
flow/Rules Normal file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env ruby
compile '/index.asciidoc' do
filter :asciidoctor, attributes: 'showtitle=true'
layout '/home.html'
write item.identifier.without_ext + '.html'
end
compile '/projects/**/*.asciidoc' do
filter :asciidoctor, attributes: 'showtitle=true'
layout '/projects.html'
write item.identifier.without_ext + '.html'
end
passthrough '/favicon.ico'
passthrough '/css/*.css'
layout '/**/*', :erb

View file

@ -0,0 +1,145 @@
:root {
--background: #1a1b26;
--background-dark: #16161e;
--foreground: #ffffff;
--link: #7aa2f7;
--link-hover: #bb9af7;
}
* {
margin: 0;
padding: 0;
font-family: sans-serif;
}
body {
background: var(--background);
color: var(--foreground);
}
a {
text-decoration: none;
}
a:link, a:visited {
color: var(--link);
}
a:hover {
color: var(--link-hover);
}
#main {
position: absolute;
top: 40px;
left: 280px;
width: 800px;
}
#main h1 {
font-size: 40px;
font-weight: normal;
line-height: 40px;
letter-spacing: 0px;
}
#main h2 {
line-height: 20px;
margin-bottom: 20px;
}
#main h3 {
line-height: 10px;
margin-bottom: 10px;
}
#main p {
margin: 20px 0;
font-size: 15px;
line-height: 20px;
}
#main ul, #main ol {
margin: 20px;
}
#main li {
font-size: 15px;
line-height: 20px;
}
#main ul li {
list-style-type: square;
}
#sidebar {
background: var(--background-dark);
position: fixed;
top: 0px;
left: 0px;
width: 200px;
height: 100%;
padding: 30px 20px 0 0;
#border-right: 1px solid #ccc;
text-align: right;
}
#sidebar h2 {
text-transform: uppercase;
font-size: 13px;
letter-spacing: 1px;
line-height: 20px;
}
#sidebar ul {
list-style-type: none;
margin: 20px 0;
}
#sidebar li {
font-size: 14px;
line-height: 20px;
}
#navigation ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: var(--background-dark);
position: fixed;
top: 0;
left: 220px;
width: 100%;
}
#navigation li {
float: left;
border-right: 1px solid #bbb;
}
#navigation li:last-child {
border-right: none;
}
#navigation a {
float: left;
text-align: center;
padding: 5px 10px;
}
code {
font-family: monospace;
}
pre code {
display: block;
background: var(--background-dark);
color: #a9b1d6;
border-radius: .3rem;
line-height: 15px;
margin-bottom: 20px;
overflow-x: scroll;
padding: 1.2em;
white-space: pre;
}

View file

@ -0,0 +1,13 @@
---
title: About Flow
---
= Flow
My new Flow website.
== To Do
- The main body of this page is a short summary of myself, the platform and projects (maybe).
- Create a good theme.
- Figure out a strategy to build and host the website.

20
flow/layouts/home.html Normal file
View file

@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<html lang="en">
<%= render '/partials/head.html' %>
<body>
<%= render '/partials/navigation.html' %>
<div id="main">
<%= yield %>
</div>
<div id="sidebar">
<h2>My Profiles</h2>
<ul>
<%= profiles %>
</ul>
<h2>Flow Services</h2>
<ul>
<%= services %>
</ul>
</div>
</body>
</html>

View file

@ -0,0 +1,7 @@
<head>
<meta charset="utf-8">
<title>Flow | <%= @item[:title] %></title>
<link rel="stylesheet" href="/css/stylesheet.css">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
<meta name="generator" content="Nanoc <%= Nanoc::VERSION %>">
</head>

View file

@ -0,0 +1,6 @@
<div id="navigation">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/projects/">Projects</a></li>
</ul>
</div>

View file

@ -0,0 +1,16 @@
<!DOCTYPE HTML>
<html lang="en">
<%= render '/partials/head.html' %>
<body>
<%= render '/partials/navigation.html' %>
<div id="main">
<%= yield %>
</div>
<div id="sidebar">
<h2>My Projects</h2>
<ul>
<%= projects %>
</ul>
</div>
</body>
</html>

1
flow/lib/helpers.rb Normal file
View file

@ -0,0 +1 @@
use_helper Nanoc::Helpers::Rendering

9
flow/lib/profiles.rb Normal file
View file

@ -0,0 +1,9 @@
def profiles
out = +''
@config[:profiles].each do |profile|
out << "<li><a href=\"#{profile[:url]}\" rel=\"me\">#{profile[:name]}</a></li>\n"
end
out
end

9
flow/lib/projects.rb Normal file
View file

@ -0,0 +1,9 @@
def projects
out = +''
@config[:projects].each do |project|
out << "<li><a href=\"/projects/#{project[:name]}/\">#{project[:name]}</a></li>\n"
end
out
end

9
flow/lib/services.rb Normal file
View file

@ -0,0 +1,9 @@
def services
out = +''
@config[:services].each do |service|
out << "<li><a href=\"#{service[:url]}\">#{service[:name]}</a></li>\n"
end
out
end

58
flow/nanoc.yaml Normal file
View file

@ -0,0 +1,58 @@
# A list of file extensions that Nanoc will consider to be textual rather than
# binary. If an item with an extension not in this list is found, the file
# will be considered as binary.
text_extensions:
- 'adoc'
- 'asciidoc'
- 'css'
- 'erb'
- 'html'
- 'rb'
prune:
auto_prune: true
data_sources:
- type: filesystem
encoding: utf-8
environments:
default:
site_name: Flow (Local)
base_url: http://localhost:3000
development:
site_name: Flow (Dev)
base_url: https://dan.anglin
production:
site_name: Flow
base_url: https://dananglin.me.uk
profiles:
- name: Fediverse
url: https://freeflow.dananglin.me.uk/@dan
- name: Code Flow
url: https://codeflow.dananglin.me.uk/dananglin
- name: Codeberg
url: https://codeberg.org/dananglin
- name: GitHub
url: https://github.com/dananglin
- name: GitLab
url: https://gitlab.com/dananglin
- name: Keyoxide
url: https://keyoxide.org/3A8B819A5E8795D75FDFF360B135D610070D4526
projects:
- name: pelican
repository_url: https://codeflow.dananglin.me.uk/apollo/pelican.git
branch: flow-website-support
documentation_root: docs
- name: spruce
repository_url: https://codeflow.dananglin.me.uk/apollo/spruce.git
branch: flow-website-support
documentation_root: docs
services:
- name: "Code Flow"
url: https://codeflow.dananglin.me.uk
- name: "Free Flow"
url: https://freeflow.dananglin.me.uk

6
go.mod
View file

@ -1,5 +1,3 @@
module codeflow.dananglin.me.uk/flow/landing
module codeflow.dananglin.me.uk/flow/website
go 1.21.0
require github.com/magefile/mage v1.15.0
go 1.22

2
go.sum
View file

@ -1,2 +0,0 @@
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=

36
internal/build/go.mod Normal file
View file

@ -0,0 +1,36 @@
module flow-website-build
go 1.22.0
require (
github.com/go-git/go-git/v5 v5.11.0
github.com/goccy/go-yaml v1.11.3
)
require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.10.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)

164
internal/build/go.sum Normal file
View file

@ -0,0 +1,164 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU=
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU=
github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4=
github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/goccy/go-yaml v1.11.3 h1:B3W9IdWbvrUu2OYQGwvU1nZtvMQJPBKgBUuweJjLj6I=
github.com/goccy/go-yaml v1.11.3/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ=
github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View file

@ -0,0 +1,13 @@
//go:build ignore
package main
import (
"os"
"github.com/magefile/mage/mage"
)
func main() {
os.Exit(mage.Main())
}

View file

@ -0,0 +1,16 @@
//go:build mage
package main
import (
"fmt"
"os"
)
func changeToProjectRoot() error {
if err := os.Chdir("../.."); err != nil {
return fmt.Errorf("unable to change directory; %w", err)
}
return nil
}

View file

@ -0,0 +1,209 @@
//go:build mage
package main
import (
"fmt"
"io"
"log/slog"
"os"
"path/filepath"
"strings"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/goccy/go-yaml"
)
type projectsConfig struct {
Projects []project `yaml:"projects"`
}
type project struct {
Name string `yaml:"name"`
RepositoryURL string `yaml:"repository_url"`
Commit string `yaml:"commit"`
Tag string `yaml:"tag"`
Branch string `yaml:"branch"`
GitReference string `yaml:"git_reference"`
DocumentationRoot string `yaml:"documentation_root"`
}
var (
configFile = "./flow/nanoc.yaml"
projectsDirectory = "./flow/content/projects"
)
func Projects() error {
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
slog.SetDefault(logger)
if err := changeToProjectRoot(); err != nil {
return fmt.Errorf("unable to change to the project's root directory; %w", err)
}
projects, err := parseProjectsConfig()
if err != nil {
return fmt.Errorf("unable to parse the projects configuration; %w", err)
}
for _, project := range projects.Projects {
clonedDirectory, err := cloneProject(project)
if err != nil {
return fmt.Errorf("unable to clone %q; %w", project.Name, err)
}
documentationDir := filepath.Join(clonedDirectory, project.DocumentationRoot)
if err := copyDocumentation(documentationDir, project.Name); err != nil {
return fmt.Errorf("unable to copy the documentation from %q; %w", project.Name, err)
}
}
return nil
}
func parseProjectsConfig() (projectsConfig, error) {
slog.Info("Parsing configuration.", "config file", configFile)
var config projectsConfig
data, err := os.ReadFile(configFile)
if err != nil {
return config, fmt.Errorf("unable to read %q; %w", configFile, err)
}
if err := yaml.Unmarshal(data, &config); err != nil {
return config, fmt.Errorf("unable to Unmarshal the configuration; %w", err)
}
slog.Info("Configuration parsed successfully.")
return config, nil
}
func cloneProject(p project) (string, error) {
slog.Info("Cloning the project repository.", "repository", p.RepositoryURL)
var (
reference plumbing.ReferenceName
singleBranch bool
depth int
)
if p.Tag != "" {
reference = plumbing.NewTagReferenceName(p.Tag)
singleBranch = false
depth = 1
} else if p.Branch != "" {
reference = plumbing.NewBranchReferenceName(p.Branch)
singleBranch = true
depth = 1
} else {
reference = plumbing.Main
singleBranch = false
depth = 0
}
cloneDir, err := os.MkdirTemp("", p.Name)
if err != nil {
return "", fmt.Errorf("unable to create the temporary clone directory; %w", err)
}
options := git.CloneOptions{
URL: p.RepositoryURL,
Progress: nil,
ReferenceName: reference,
SingleBranch: singleBranch,
Depth: depth,
}
repository, err := git.PlainClone(cloneDir, false, &options)
if err != nil {
return "", fmt.Errorf("unable to clone the repository; %w", err)
}
if p.Commit == "" {
return cloneDir, nil
}
worktree, err := repository.Worktree()
if err != nil {
return "", fmt.Errorf("unable to retrieve the work tree; %w", err)
}
checkoutOptions := git.CheckoutOptions{
Hash: plumbing.NewHash(p.Commit),
Create: false,
}
if err := worktree.Checkout(&checkoutOptions); err != nil {
return "", fmt.Errorf("unable to checkout %q; %w", p.Commit, err)
}
slog.Info("Project cloned successfully.")
return cloneDir, nil
}
func copyDocumentation(inputDirectory, projectName string) error {
outputDirectory := filepath.Join(projectsDirectory, projectName)
slog.Info("Copying documentation.", "project", projectName, "source", inputDirectory, "destination", outputDirectory)
defer os.RemoveAll(inputDirectory)
files, err := os.ReadDir(inputDirectory)
if err != nil {
return fmt.Errorf("unable to read files from %q; %w", inputDirectory, err)
}
if len(files) == 0 {
return nil
}
if err := os.MkdirAll(outputDirectory, 0o750); err != nil {
return fmt.Errorf("unable to create %q; %w", outputDirectory, err)
}
for _, file := range files {
if file.IsDir() || !strings.HasSuffix(file.Name(), ".asciidoc") {
continue
}
inputPath := filepath.Join(inputDirectory, file.Name())
outputPath := filepath.Join(projectsDirectory, projectName, file.Name())
err := func() error {
inputFile, err := os.Open(inputPath)
if err != nil {
return fmt.Errorf("unable to open %q; %w", inputPath, err)
}
defer inputFile.Close()
outputFile, err := os.Create(outputPath)
if err != nil {
return fmt.Errorf("unable to create %q; %w", outputPath, err)
}
defer outputFile.Close()
if _, err := io.Copy(outputFile, inputFile); err != nil {
return fmt.Errorf(
"unable to copy the contents from %q to %q; %w",
inputPath,
outputPath,
err,
)
}
return nil
}()
if err != nil {
return err
}
}
slog.Info("Documentation copied successfully.")
return nil
}

View file

@ -1,75 +0,0 @@
package main
import (
"fmt"
"strings"
)
type linkParseError struct {
msg string
}
func (e linkParseError) Error() string {
return "link parse error: " + e.msg
}
type link struct {
Title string
URL string
Rel string
}
func (l link) String() string {
return fmt.Sprintf("Title: %s, URL: %s, Rel: %s", l.Title, l.URL, l.Rel)
}
type links []link
func (l *links) Set(value string) error {
linkAttributes := strings.Split(value, ",")
lenLinkAttributes := len(linkAttributes)
if lenLinkAttributes != 2 && lenLinkAttributes != 3 {
return linkParseError{msg: fmt.Sprintf("unexpected number of attributes found %s, want 2 or 3, got %d", value, lenLinkAttributes)}
}
var thisLink link
for _, attr := range linkAttributes {
split := strings.Split(attr, "=")
switch strings.ToLower(split[0]) {
case "title":
thisLink.Title = split[1]
case "url":
thisLink.URL = split[1]
case "rel":
thisLink.Rel = split[1]
}
}
if thisLink.Title == "" {
return linkParseError{msg: fmt.Sprintf("the title attribute is missing from %s", value)}
}
if thisLink.URL == "" {
return linkParseError{msg: fmt.Sprintf("the URL attribute is missing from %s", value)}
}
*l = append(*l, thisLink)
return nil
}
func (l *links) String() string {
if len(*l) == 0 {
return ""
}
var builder strings.Builder
for _, link := range *l {
fmt.Fprintln(&builder, link)
}
return builder.String()
}

8
mage Executable file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
cd ./internal/build
mage $@

View file

@ -1,60 +0,0 @@
//go:build mage
// +build mage
package main
import (
"os"
"github.com/magefile/mage/sh"
)
var Default = Build
var binary = "landing"
// Test run the go tests.
// To enable verbose mode set GO_TEST_VERBOSE=1.
// To enable coverage mode set GO_TEST_COVER=1.
func Test() error {
goTest := sh.RunCmd("go", "test")
args := []string{"./..."}
if os.Getenv("GO_TEST_VERBOSE") == "1" {
args = append(args, "-v")
}
if os.Getenv("GO_TEST_COVER") == "1" {
args = append(args, "-cover")
}
return goTest(args...)
}
// Lint runs golangci-lint against the code.
func Lint() error {
return sh.RunV("golangci-lint", "run", "--color", "always")
}
// Build build the executable.
func Build() error {
os.Setenv("GOOS", "linux")
os.Setenv("GOARCH", "amd64")
os.Setenv("CGO_ENABLED", "0")
return sh.Run("go", "build", "-ldflags=-s -w", "-a", "-o", binary, ".")
}
// Clean clean the workspace.
func Clean() error {
if err := sh.Rm(binary); err != nil {
return err
}
if err := sh.Run("go", "clean", "./..."); err != nil {
return err
}
return nil
}

102
main.go
View file

@ -4,40 +4,27 @@ import (
"embed"
"flag"
"fmt"
"html/template"
"io/fs"
"log/slog"
"net/http"
"os"
"strings"
"time"
)
//go:embed web/static/*
var staticFS embed.FS
//go:embed web/html/*
var htmlTemplates embed.FS
//go:embed flow/output/*
var webFS embed.FS
func main() {
var (
address string
profiles links
services links
)
var address string
flag.StringVar(&address, "address", "0.0.0.0:8080", "The address that the web server will listen on")
flag.Var(&services, "service", "A list of service links")
flag.Var(&profiles, "profile", "A list of profile links")
flag.Parse()
setupLogging()
mux, err := routes(services, profiles)
mux, err := routes()
if err != nil {
slog.Error("Unable to create the Mux", "error", err)
os.Exit(1)
}
server := http.Server{
@ -47,98 +34,33 @@ func main() {
ReadTimeout: 5 * time.Second,
}
slog.Info("Starting web application.", "address", address)
slog.Info("Starting the Flow website.", "address", address)
err = server.ListenAndServe()
if err != nil {
slog.Error("Failed to run the web application", "error", err)
if err := server.ListenAndServe(); err != nil {
slog.Error("Failed to run the website", "error", err)
}
}
func routes(services, profiles links) (*http.ServeMux, error) {
func routes() (*http.ServeMux, error) {
mux := http.NewServeMux()
staticRootFS, err := fs.Sub(staticFS, "web/static")
rootFS, err := fs.Sub(webFS, "flow/output")
if err != nil {
return nil, fmt.Errorf("unable to create the static root file system; %w", err)
}
fileServer := http.FileServer(http.FS(staticRootFS))
mux.Handle("/static/", http.StripPrefix("/static", neuter(fileServer)))
mux.HandleFunc("/", landing(services, profiles))
fileserver := http.FileServer(http.FS(rootFS))
mux.Handle(http.MethodGet + " /", fileserver)
return mux, nil
}
func neuter(next http.Handler) http.Handler {
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
if strings.HasSuffix(request.URL.Path, "/") {
notFound(writer)
return
}
next.ServeHTTP(writer, request)
})
}
func landing(services, profiles links) func(http.ResponseWriter, *http.Request) {
return func(writer http.ResponseWriter, request *http.Request) {
if request.URL.Path != "/" {
notFound(writer)
return
}
if request.Method != http.MethodGet {
writer.Header().Set("Allow", http.MethodGet)
clientError(writer, http.StatusMethodNotAllowed)
return
}
tmpl, err := template.New("base").ParseFS(htmlTemplates, "web/html/base.tmpl.html")
if err != nil {
serverError(writer, fmt.Errorf("error parsing the HTML template; %w", err))
return
}
links := struct {
Services links
Profiles links
}{
Services: services,
Profiles: profiles,
}
if err = tmpl.Execute(writer, &links); err != nil {
serverError(writer, fmt.Errorf("error rendering the HTML templates; %w", err))
}
}
}
func notFound(w http.ResponseWriter) {
clientError(w, http.StatusNotFound)
}
func clientError(w http.ResponseWriter, status int) {
http.Error(w, http.StatusText(status), status)
}
func serverError(w http.ResponseWriter, err error) {
slog.Error(err.Error())
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
func setupLogging() {
opts := slog.HandlerOptions{
AddSource: false,
}
logger := slog.New(slog.NewJSONHandler(os.Stdout, &opts))
logger := slog.New(slog.NewTextHandler(os.Stdout, &opts))
slog.SetDefault(logger)
}

View file

@ -1,31 +0,0 @@
{{ define "base" }}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dan Anglin | Flow Platform</title>
<link rel="stylesheet" href="/static/css/stylesheet.css">
<link rel="icon" type="image/x-icon" href="/static/img/favicon.ico">
</head>
<body>
<h1>Flow Platform</h1>
{{ if gt (len .Services) 0 }}
<h2>Services</h2>
<div class="links">
{{- range .Services }}
<p><a href="{{ .URL }}"{{ if gt (len .Rel) 0 }} rel="{{ .Rel }}"{{ end }}>{{ .Title }}</a></p>
{{ end }}
</div>
{{ end }}
{{ if gt (len .Profiles) 0 }}
<h2>My Profiles</h2>
<div class="links">
{{- range .Profiles }}
<p><a href="{{ .URL }}"{{ if gt (len .Rel) 0 }} rel="{{ .Rel }}"{{ end }}>{{ .Title }}</a></p>
{{ end }}
</div>
{{ end }}
</body>
</html>
{{ end }}

View file

@ -1,33 +0,0 @@
body {
background-color: #1e1c31;
text-align: center;
font-family: sans-serif;
font-weight: 600;
}
h1, h2{
color: white;
}
body .links {
max-width: 500px;
margin: auto;
text-align: center;
}
body .links p a {
display: block;
background-color: #296ae2;
color: Thistle;
text-decoration: none;
padding: 15px;
margin-bottom: 10px;
transition: 0.5s;
border-radius: 5px;
}
body .links p a:hover, a:active {
background-color: #719dee;
color: White;
transition: 0.5s;
}

BIN
web/static/gpg/public.asc (Stored with Git LFS)

Binary file not shown.