-
Notifications
You must be signed in to change notification settings - Fork 7.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CI - no absolute links to local pages #849
Changes from 16 commits
464ce98
5b3cbf7
f9dad1a
80381c9
15e07d6
39ea6e4
f708add
da5c4d2
09d4a6f
4cbff2c
bb6a13b
ed9b3f4
7cf627c
dc8d5ed
6c9d099
5e3fbb8
8f1bc38
51df23e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[submodule "tests/src/github.com/gdevillele/frontparser"] | ||
path = tests/src/github.com/gdevillele/frontparser | ||
url = https://github.com/gdevillele/frontparser.git | ||
branch = f28e87c7b9dae139855b574e96f22822986249a8 | ||
[submodule "tests/src/golang.org/x/net"] | ||
path = tests/src/golang.org/x/net | ||
url = https://go.googlesource.com/net | ||
branch = 45e771701b814666a7eb299e6c7a57d0b1799e91 | ||
[submodule "tests/src/gopkg.in/yaml.v2"] | ||
path = tests/src/gopkg.in/yaml.v2 | ||
url = https://gopkg.in/yaml.v2 | ||
branch = a5b47d31c556af34a302ce5d659e6fea44d90de0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ enabled](troubleshoot.md#virtualization-must-be-enabled) in Troubleshooting. | |
<p /> | ||
* Nested virtualization scenarios, such as running Docker for Windows on a VMWare or Parallels instance, might work, but come with no guarantees (i.e., not officially supported). | ||
<p /> | ||
* **What the Docker for Windows install includes**: The installation provides [Docker Engine](https://docs.docker.com/engine/userguide/intro/), Docker CLI client, [Docker Compose](https://docs.docker.com/compose/overview/), and [Docker Machine](https://docs.docker.com/machine/overview/). | ||
* **What the Docker for Windows install includes**: The installation provides [Docker Engine](/engine/userguide/intro/), Docker CLI client, [Docker Compose](/compose/overview/), and [Docker Machine](/machine/overview/). | ||
|
||
### About Windows containers and Windows Server 2016 | ||
|
||
|
@@ -478,15 +478,15 @@ You can configure options on the Docker daemon in the given JSON configuration f | |
|
||
![Docker Daemon](images/docker-daemon.png) | ||
|
||
For a full list of options on the Docker daemon, see <a href="https://docs.docker.com/engine/reference/commandline/dockerd/" target="_blank">daemon</a> in the Docker Engine command line reference. | ||
For a full list of options on the Docker daemon, see [daemon](/engine/reference/commandline/dockerd/) in the Docker Engine command line reference. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You changed the functionality of this link by removing the target attribute... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mstanleyjones I can use this syntax with Kramdown: |
||
|
||
In that topic, see also: | ||
|
||
* [Daemon configuration file](https://docs.docker.com/engine/reference/commandline/dockerd/#/daemon-configuration-file) | ||
* [Daemon configuration file](/engine/reference/commandline/dockerd/#/daemon-configuration-file) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not introduced here, but these should point to the .md file if possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mstanleyjones I can fix it if you're sure we should always link to md files There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mstanleyjones well if I do this the redirect loses the anchor link. You can try by yourself: https://docs.docker.com/engine/reference/commandline/dockerd/#/daemon-configuration-file versus https://docs.docker.com/engine/reference/commandline/dockerd.md#/daemon-configuration-file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The correct Markdown should be: [Daemon configuration file](/engine/reference/commandline/dockerd.md#daemon-configuration-file) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mstanleyjones https://docs.docker.com/engine/reference/commandline/dockerd.md#daemon-configuration-file doesn't work either... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe it expects relative URLs; |
||
|
||
* [Linux configuration file](https://docs.docker.com/engine/reference/commandline/dockerd/#/linux-configuration-file) | ||
* [Linux configuration file](/engine/reference/commandline/dockerd/#/linux-configuration-file) | ||
|
||
* [Windows configuration file](https://docs.docker.com/engine/reference/commandline/dockerd/#/windows-configuration-file) | ||
* [Windows configuration file](/reference/commandline/dockerd/#/windows-configuration-file) | ||
|
||
Note that updating these settings requires a reconfiguration and reboot of the Linux VM. | ||
|
||
|
@@ -557,7 +557,7 @@ the FAQs.) | |
|
||
The **Advanced** daemon settings provide the original option to directly edit | ||
the JSON configuration file for the <a | ||
href="https://docs.docker.com/engine/reference/commandline/dockerd/" | ||
href="/engine/reference/commandline/dockerd/" | ||
target="_blank">daemon</a>. (This is the only option currently available on stable releases, as described in [Docker daemon](#docker-daemon).) | ||
|
||
![Docker Daemon](images/docker-daemon_advanced.png) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ For a complete list of `docker-machine` subcommands, see the [Docker Machine sub | |
|
||
Users using their own Docker Registry will experience `x509: certificate signed by unknown authority` | ||
error messages if their registry is signed by custom root Certificate Authority and it is | ||
not registered with Docker Engine. As discussed in the [Docker Engine documentation](https://docs.docker.com/engine/security/certificates/#/understanding-the-configuration) | ||
not registered with Docker Engine. As discussed in the [Docker Engine documentation](/engine/security/certificates/#/understanding-the-configuration) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, link to the .md if possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mstanleyjones Same as above... Losing the anchor link There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mstanleyjones Also, one important point. Currently it is somehow better to use a path of this form: https://docs.docker.com/engine/reference/commandline/dockerd/ Because the non-md form leads you right to the page you want. While the md form returns a terrible 404 error with a client side JS script that takes you to the non-md path... We already mentioned that in the past, I really think it's an issue for SEO. But I also think it makes more sense to link to local markdowns within markdowns. Maybe we should just update these links at build time. |
||
certificates should be placed at `/etc/docker/certs.d/hostname/ca.crt` | ||
where `hostname` is your Registry server's hostname. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"golang.org/x/net/html" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
var countLinks = 0 | ||
var countImages = 0 | ||
|
||
// TestURLs tests if we're not using absolute paths for URLs | ||
// when pointing to local pages. | ||
func TestURLs(t *testing.T) { | ||
count := 0 | ||
|
||
filepath.Walk("/usr/src/app/allvbuild", func(path string, info os.FileInfo, err error) error { | ||
|
||
relPath := strings.TrimPrefix(path, "/usr/src/app/allvbuild") | ||
|
||
isArchive, err := regexp.MatchString(`^/v[0-9]+\.[0-9]+/.*`, relPath) | ||
if err != nil { | ||
t.Error(err.Error(), "-", relPath) | ||
} | ||
// skip archives for now, only test URLs in current version | ||
// TODO: test archives | ||
if isArchive { | ||
return nil | ||
} | ||
|
||
if err != nil { | ||
t.Error(err.Error(), "-", relPath) | ||
} | ||
b, htmlBytes, err := isHTML(path) | ||
if err != nil { | ||
t.Error(err.Error(), "-", relPath) | ||
} | ||
// don't check non-html files | ||
if b == false { | ||
return nil | ||
} | ||
|
||
count++ | ||
|
||
err = testURLs(htmlBytes) | ||
if err != nil { | ||
t.Error(err.Error(), "-", relPath) | ||
} | ||
return nil | ||
}) | ||
|
||
fmt.Println("found", count, "html files (excluding archives)") | ||
fmt.Println("found", countLinks, "links (excluding archives)") | ||
fmt.Println("found", countImages, "images (excluding archives)") | ||
} | ||
|
||
// testURLs tests if we're not using absolute paths for URLs | ||
// when pointing to local pages. | ||
func testURLs(htmlBytes []byte) error { | ||
|
||
reader := bytes.NewReader(htmlBytes) | ||
|
||
z := html.NewTokenizer(reader) | ||
|
||
for { | ||
tt := z.Next() | ||
|
||
switch tt { | ||
case html.ErrorToken: | ||
// End of the document, we're done | ||
return nil | ||
case html.StartTagToken: | ||
t := z.Token() | ||
|
||
url := "" | ||
|
||
// check tag types | ||
switch t.Data { | ||
case "a": | ||
countLinks++ | ||
ok, href := getHref(t) | ||
// skip, it may just be an anchor | ||
if !ok { | ||
break | ||
} | ||
url = href | ||
|
||
case "img": | ||
countImages++ | ||
ok, src := getSrc(t) | ||
if !ok { | ||
return errors.New("img with no src: " + t.String()) | ||
} | ||
url = src | ||
} | ||
|
||
// there's an url to test! | ||
if url != "" { | ||
if strings.HasPrefix(url, "http://docs.docker.com") || strings.HasPrefix(url, "https://docs.docker.com") { | ||
return errors.New("found absolute link: " + t.String()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// helpers | ||
|
||
func getHref(t html.Token) (ok bool, href string) { | ||
for _, a := range t.Attr { | ||
if a.Key == "href" { | ||
href = a.Val | ||
ok = true | ||
} | ||
} | ||
return | ||
} | ||
|
||
func getSrc(t html.Token) (ok bool, src string) { | ||
for _, a := range t.Attr { | ||
if a.Key == "src" { | ||
src = a.Val | ||
ok = true | ||
} | ||
} | ||
return | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/gdevillele/frontparser" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
) | ||
|
||
// isPublishedMarkdown returns wether a file is a published markdown or not | ||
// as a convenience it also returns the markdown bytes to avoid reading files twice | ||
func isPublishedMarkdown(path string) (bool, []byte, error) { | ||
if strings.HasSuffix(path, ".md") { | ||
fileBytes, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return false, nil, err | ||
} | ||
if frontparser.HasFrontmatterHeader(fileBytes) { | ||
fm, _, err := frontparser.ParseFrontmatterAndContent(fileBytes) | ||
if err != nil { | ||
return false, nil, err | ||
} | ||
// skip markdowns that are not published | ||
if published, exists := fm["published"]; exists { | ||
if publishedBool, ok := published.(bool); ok { | ||
if publishedBool { | ||
// file is markdown, has frontmatter and is published | ||
return true, fileBytes, nil | ||
} | ||
} | ||
} else { | ||
// if "published" field is missing, it means published == true | ||
return true, fileBytes, nil | ||
} | ||
} | ||
} | ||
return false, nil, nil | ||
} | ||
|
||
// isHTML returns wether a file is an html file or not | ||
// as a convenience it also returns the markdown bytes to avoid reading files twice | ||
func isHTML(path string) (bool, []byte, error) { | ||
if strings.HasSuffix(path, ".html") { | ||
fileBytes, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return false, nil, err | ||
} | ||
return true, fileBytes, nil | ||
} | ||
return false, nil, nil | ||
} | ||
|
||
// fileExists returns true if the given file exists | ||
func fileExists(name string) bool { | ||
_, err := os.Stat(name) | ||
return err == nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not introduced here, but shouldn't this be a link to a .md file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mstanleyjones I have no idea... 😕