Skip to content

Commit 5d925ee

Browse files
authored
Merge pull request #545 from vbatts/html_img
docs: image base reference
2 parents a896cfc + fec31f4 commit 5d925ee

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/oci-validate-examples
22
output
3+
header.html

.tool/genheader.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2017 The Linux Foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"bytes"
19+
"fmt"
20+
"os"
21+
"os/exec"
22+
"strings"
23+
"text/template"
24+
25+
specs "github.com/opencontainers/image-spec/specs-go"
26+
)
27+
28+
var headerTemplate = template.Must(template.New("gen").Parse(`<title>image-spec {{.Version}}</title>
29+
<base href="https://raw.githubusercontent.com/opencontainers/image-spec/{{.Branch}}/">`))
30+
31+
type Obj struct {
32+
Version string
33+
Branch string
34+
}
35+
36+
func main() {
37+
obj := Obj{
38+
Version: specs.Version,
39+
Branch: specs.Version,
40+
}
41+
if strings.HasSuffix(specs.Version, "-dev") {
42+
cmd := exec.Command("git", "log", "-1", `--pretty=%H`, "HEAD")
43+
var out bytes.Buffer
44+
cmd.Stdout = &out
45+
cmd.Stderr = os.Stderr
46+
if err := cmd.Run(); err != nil {
47+
fmt.Fprintln(os.Stderr, err)
48+
os.Exit(1)
49+
}
50+
51+
obj.Branch = strings.Trim(out.String(), " \n\r")
52+
}
53+
headerTemplate.Execute(os.Stdout, obj)
54+
}

Makefile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,16 @@ $(OUTPUT_DIRNAME)/$(DOC_FILENAME).pdf: $(DOC_FILES) $(FIGURE_FILES)
6868
$(PANDOC) -f markdown_github -t latex --latex-engine=xelatex -o $(PANDOC_DST)$@ $(patsubst %,$(PANDOC_SRC)%,$(DOC_FILES))
6969
ls -sh $(shell readlink -f $@)
7070

71-
$(OUTPUT_DIRNAME)/$(DOC_FILENAME).html: $(DOC_FILES) $(FIGURE_FILES)
71+
$(OUTPUT_DIRNAME)/$(DOC_FILENAME).html: header.html $(DOC_FILES) $(FIGURE_FILES)
7272
@mkdir -p $(OUTPUT_DIRNAME)/ && \
7373
cp -ap img/ $(shell pwd)/$(OUTPUT_DIRNAME)/&& \
74-
$(PANDOC) -f markdown_github -t html5 -o $(PANDOC_DST)$@ $(patsubst %,$(PANDOC_SRC)%,$(DOC_FILES))
74+
$(PANDOC) -f markdown_github -t html5 -H $(PANDOC_SRC)/header.html --standalone -o $(PANDOC_DST)$@ $(patsubst %,$(PANDOC_SRC)%,$(DOC_FILES))
7575
ls -sh $(shell readlink -f $@)
7676
endif
7777

78+
header.html: .tool/genheader.go specs-go/version.go
79+
go run .tool/genheader.go > $@
80+
7881
validate-examples: schema/fs.go
7982
go test -run TestValidate ./schema
8083

@@ -98,7 +101,6 @@ test: schema/fs.go
98101
img/%.png: img/%.dot
99102
dot -Tpng $^ > $@
100103

101-
.PHONY: .gitvalidation
102104

103105
# When this is running in travis, it will only check the travis commit range
104106
.gitvalidation:
@@ -109,8 +111,6 @@ else
109111
git-validation -v -run DCO,short-subject,dangling-whitespace -range $(EPOCH_TEST_COMMIT)..HEAD
110112
endif
111113

112-
.PHONY: install.tools
113-
114114
install.tools: .install.gitvalidation .install.glide .install.glide-vc
115115

116116
.install.gitvalidation:
@@ -123,13 +123,16 @@ install.tools: .install.gitvalidation .install.glide .install.glide-vc
123123
go get -u github.com/sgotti/glide-vc
124124

125125
clean:
126-
rm -rf *~ $(OUTPUT_DIRNAME)
126+
rm -rf *~ $(OUTPUT_DIRNAME) header.html
127127

128128
.PHONY: \
129129
validate-examples \
130130
check-license \
131131
clean \
132132
lint \
133+
install.tools \
133134
docs \
134135
test \
136+
.gitvalidation \
137+
schema/fs.go \
135138
schema-fs

0 commit comments

Comments
 (0)