Put each bit of spec in its own directory

I want to change the URLs for the spec sections on the website from
<version>/<section>.html to <section>/<version>.html, to better reflect how we
do the versioning.

This puts each bit of spec in its own directory, updates the index to point to
the right place, and fixes continuserv to deal with directories as well as
files.

This will probably require fixes to the speculator too, but I'll have to come
back to that.
This commit is contained in:
Richard van der Hoff 2016-05-05 18:26:17 +01:00
parent a8eed29e9f
commit 01f8173c84
4 changed files with 66 additions and 34 deletions

View file

@ -103,7 +103,7 @@ func makeWalker(base string, w *fsnotify.Watcher) filepath.WalkFunc {
// log.Printf("Adding watch on %s", path)
if err := w.Add(path); err != nil {
log.Fatalf("Failed to add watch: %v", err)
log.Fatalf("Failed to add watch on %s: %v", path, err)
}
return nil
}
@ -166,19 +166,34 @@ func populateOnce(dir string) {
toServe.Store(bytesOrErr{nil, fmt.Errorf("error generating spec: %v\nOutput from gendoc:\n%v", err, b.String())})
return
}
fis, err := ioutil.ReadDir(path.Join(dir, "scripts", "gen"))
if err != nil {
toServe.Store(bytesOrErr{nil, err})
return
}
files := make(map[string][]byte)
for _, fi := range fis {
bytes, err := ioutil.ReadFile(path.Join(dir, "scripts", "gen", fi.Name()))
base := path.Join(dir, "scripts", "gen")
walker := func(path string, info os.FileInfo, err error) error {
if err != nil {
toServe.Store(bytesOrErr{nil, fmt.Errorf("error reading spec: %v", err)})
return
return err
}
files[fi.Name()] = bytes
if info.IsDir() {
return nil
}
rel, err := filepath.Rel(base, path)
if err != nil {
return fmt.Errorf("Failed to get relative path of %s: %v", path, err)
}
bytes, err := ioutil.ReadFile(path)
if err != nil {
return err
}
files[rel] = bytes
return nil
}
err = filepath.Walk(base, walker)
if err != nil {
toServe.Store(bytesOrErr{nil, fmt.Errorf("error reading spec: %v", err)})
return
}
toServe.Store(bytesOrErr{files, nil})
}