Git Product home page Git Product logo

docsite's Introduction

docsite

A documentation site generator that fits Sourcegraph's needs:

  • Markdown source files that are browseable on the file system and readable as plain text (without custom directives or complex front matter or configuration)
  • Served by an HTTP server, not generated as static HTML files, to eliminate the need for external static site host configuration (which we found to be error-prone)
  • Provides built-in site search for all documentation versions

Usage

go get github.com/sourcegraph/docsite/cmd/docsite
docsite -h
  • docsite check: check for common problems (such as broken links)
  • docsite serve: serve the site over HTTP

To use docsite for docs.sourcegraph.com, see "Documentation site" in the Sourcegraph documentation.

Checks

The docsite check command runs various checks on your documentation site to find problems:

  • invalid links
  • broken links
  • disconnected pages (with no inlinks from other pages)

If any problems are found, it exits with a non-zero status code.

To ignore the disconnected page check for a page, add YAML ignoreDisconnectedPageCheck: true to the top matter in the beginning of the .md file. For example:

---
ignoreDisconnectedPageCheck: true
---

# My page title

Site data

The site data describes the location of its templates, assets, and content. It is a JSON object with the following properties.

  • content: a VFS URL for the Markdown content files.
  • contentExcludePattern: a regular expression specifying Markdown content files to exclude.
  • baseURLPath: the URL path where the site is available (such as / or /help/).
  • rootURL: (optional) the root URL (scheme + host). Only used for rare cases where this is absolutely necessary, such as SEO tags fox example.
  • templates: a VFS URL for the Go-style HTML templates used to render site pages.
  • assets: a VFS URL for the static assets referred to in the HTML templates (such as CSS stylesheets).
  • assetsBaseURLPath: the URL path where the assets are available (such as /assets/).
  • redirects: an object mapping URL paths (such as /my/old/page) to redirect destination URLs (such as /my/new/page).
  • check (optional): an object containing a single property ignoreURLPattern, which is a RE2 regexp of URLs to ignore when checking for broken URLs with docsite check.
  • search (optional): an object containing a single proprety skipIndexURLPattern, which is a RE2 regexp pattern that if matching any content file URL will remove that file from the search index.

The possible values for VFS URLs are:

  • A relative path to a local directory (such as ../myrepo/doc). The path is interpreted relative to the docsite.json file (if it exists) or the current working directory (if site data is specified in DOCSITE_CONFIG).

  • An absolute URL to a Zip archive (with http or https scheme). The URL can contain a fragment (such as #mydir/) to refer to a specific directory in the archive.

    If the URL fragment contains a path component * (such as #*/templates/), it matches the first top-level directory in the Zip file. (This is useful when using GitHub Zip archive URLs, such as https://codeload.github.com/alice/myrepo/zip/myrev#*/templates/. GitHub produces Zip archives with a top-level directory $REPO-$REV, such as myrepo-myrev, and using #*/templates/ makes it easy to descend into that top-level directory without needing to duplicate the myrev in the URL fragment.)

    If the URL contains the literal string $VERSION, it is replaced by the user's requested version from the URL (e.g., the URL path /@foo/bar means the version is foo). โš ๏ธ If you are using GitHub codeload.github.com archive URLs, be sure your URL contains refs/heads/$VERSION (as in https://codeload.github.com/owner/repo/zip/refs/heads/$VERSION), not just $VERSION. This prevents someone from forking your repository, pushing a commit to their fork with unauthorized content, and then crafting a URL on your documentation site that would cause users to view that unauthorized content (which may contain malicious scripts or misleading information).

Templates

The templates use Go-style HTML templates.

  • Document pages are rendered using a template named document.html.
  • Search result pages are rendered using a template named search.html.
  • The file root.html, if it exists, is loaded when rendering any template. You can define common templates in this file.

See the following examples:

Redirects

In addition to the redirects property in site data, you can also specify redirects in a text file named redirects at the top level of the assets VFS. The format is as follows:

FROM-PATH TO-URL STATUS-CODE

For example:

# Comments are allowed
/my/old/page /my/new/page 308
/another/page https://example.com/page 308

Specifying site data

The docsite tool requires site data to be available in any of the following ways:

  • A docsite.json file (or other file specified in the -config flag's search paths), as in the following example:
    {
      "content": "../sourcegraph/doc",
      "baseURLPath": "/",
      "templates": "templates",
      "assets": "assets",
      "assetsBaseURLPath": "/assets/",
      "check": {
        "ignoreURLPattern": "(^https?://)|(^#)|(^mailto:support@sourcegraph\\.com$)|(^chrome://)"
      }
    }
  • In the DOCSITE_CONFIG env var, using Zip archive URLs for templates, assets, and content, as in the following example:
    DOCSITE_CONFIG='{"templates":"https://codeload.github.com/sourcegraph/sourcegraph/zip/refs/heads/main#*/doc/_resources/templates/","assets":"https://codeload.github.com/sourcegraph/sourcegraph/zip/refs/heads/main#*/doc/_resources/assets/","content":"https://codeload.github.com/sourcegraph/sourcegraph/zip/refs/heads/$VERSION#*/doc/","baseURLPath":"/","assetsBaseURLPath":"/assets/","defaultContentBranch":"main"}' docsite serve
    

Development

Release a new version

  1. Build the Docker image for linux/amd64:

    docker build -t sourcegraph/docsite .
    
    # Use buildx if you're on M1
    docker buildx build --platform linux/amd64 -t sourcegraph/docsite .
  2. Tag and push the image to Docker Hub and GCR:

    export VERSION= # e.g. v1.9.1
    docker tag sourcegraph/docsite sourcegraph/docsite:$VERSION
    docker push sourcegraph/docsite
    docker push sourcegraph/docsite:$VERSION
  3. For internal Sourcegraph usage:

    1. Bump the deployed version by updating the SHA-256 image digest in all files that define sourcegraph/docsite:latest@sha256.
    2. Once the pull request is merged, wait for the Buildkite build to pass.
  4. For development, bump the version number in files that define DOCSITE_VERSION.

docsite's People

Contributors

bobheadxi avatar burmudar avatar camdencheek avatar cesrjimenez avatar chrismwendt avatar coury-clark avatar davejrt avatar daxmc99 avatar felixfbecker avatar gbrik avatar ijt avatar jhchabran avatar keegancsmith avatar lawngnome avatar slimsag avatar sourcegraph-bot avatar sqs avatar unknwon avatar varungandhi-src avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docsite's Issues

docsite check chokes if an empty markdown file exists

To reproduce, add an empty file with .md file extension, then run docsite check.

anic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x15927e7]

goroutine 1 [running]:
github.com/sourcegraph/docsite.(*Site).checkContentPage(0xc0001dee60, 0x0, 0x0, 0x0, 0x0)
        /Users/rb/Projects/docsite/check.go:69 +0x47
github.com/sourcegraph/docsite.(*Site).Check(0xc0001dee60, 0x1884680, 0xc0000ca000, 0x0, 0x0, 0x0, 0x100d329, 0x1d0edc0, 0x1eacd98, 0x0)
        /Users/rb/Projects/docsite/check.go:50 +0x704
main.init.0.func1(0xc0000c6010, 0x0, 0x0, 0x0, 0x0)
        /Users/rb/Projects/docsite/cmd/docsite/check.go:21 +0xb8
main.commander.run(0xc0003f60c0, 0x2, 0x2, 0xc0000be120, 0x16e2469, 0x7, 0xc00002ee40, 0xc0000c6010, 0x1, 0x1)
        /Users/rb/Projects/docsite/cmd/docsite/cmd.go:117 +0x302
main.main()
        /Users/rb/Projects/docsite/cmd/docsite/main.go:46 +0xee

Unable to load a combination of content and templates/assets locally and over http

It seems docsite can either load everything over http or everything locally, but not a combination of the two. This should work but it doesn't:

DOCSITE_CONFIG=$(cat <<-'DOCSITE'
{
  "templates": "_resources/templates",
  "content": "https://codeload.github.com/sourcegraph/sourcegraph/zip/$VERSION#*/doc/",
  "baseURLPath": "/",
  "assets": "_resources/assets",
  "assetsBaseURLPath": "/assets/"
}
DOCSITE
) docsite serve -http=localhost:5081
# Downloading site data...
Get _resources/assets: unsupported protocol scheme ""

Recognize README.md as well as index.md for index files

Dociste shouldn't force developers to use index.md instead of README.md files. READMD.md files are advantageous because GitHub, for example, will render the markdown when viewing files at the directory level if a README.md file exists.

Having docsite support both README.md and index.md files would improve user experience when browsing docs code on a code host.

Decide if a config file, frontmatter or directory and file naming control the creation of the index

This discussion needs to cement:

  • How a page is added to index
  • How the ordering and visibility of pages is controlled
  • How the link text would be controlled
  • If any validation should occur as part of PR pre-commit or PR check?

I've looked at examples from popular static site generators and most use a config file.

Config

Directory

Frontmatter

SEO the docsite: handbook and docs

  1. Add frontmatter metadata to all pages - at the very least
    description:
    canonical_path:
    twitter_image:

  2. Generate a sitemap file for all of the published pages i.e.
    for handbook: about.sourcegraph.com/sitemap-handbook.xml
    for docs: docs.sourcegraph.com/sitemap.xml

Support Sourcegraph notebooks on docs site

Our developer docs contain some code walkthroughs that would work really well as Sourcegraph notebooks. For example, I tried converting the Life of a search query docs to a notebook and found it more readable. It'd be great if docs.sourcegraph.com could show notebooks like this. If we had notebooks throughout the docs, maybe more users would learn about them and see how useful they are.

Currently, the way to do this would be to create a public notebook on https://sourcegraph.com/notebooks, and then embed that in an iframe in a docs page. But this would mean separating out important documentation from the sourcegraph/sourcegraph repo where it currently lives. It seems best to keep all the docs in one place, living alongside the code.

Maybe this would be a new notebooks feature? You could just point to the URL of a running Sourcegraph instance, plus the location of a .snb.md file, and it will render it?

docsite panics when invalid links are present

See https://buildkite.com/sourcegraph/sourcegraph/builds/39093#1772d252-e134-4531-92a5-aa90760eace0

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xc0 pc=0x12f1916]

goroutine 1 [running]:
net/http.(*ServeMux).ServeHTTP(0xc003c064c0, 0x1887940, 0xc003c06540, 0x0)
	/usr/local/go/src/net/http/server.go:2367 +0x26
github.com/sourcegraph/docsite.(*Site).checkContentPage.func2(0xc002b5b844, 0x3)
	/Users/nick/dev/gopath/pkg/mod/github.com/sourcegraph/[email protected]/check.go:109 +0x188
github.com/sourcegraph/docsite.walkHTMLDocument(0xc002d591f0, 0xc0009bbc50)
	/Users/nick/dev/gopath/pkg/mod/github.com/sourcegraph/[email protected]/check.go:156 +0x10d
github.com/sourcegraph/docsite.walkHTMLDocument(0xc002d59110, 0xc0009bbc50)
	/Users/nick/dev/gopath/pkg/mod/github.com/sourcegraph/[email protected]/check.go:166 +0x5e
github.com/sourcegraph/docsite.walkHTMLDocument(0xc002d58d90, 0xc0009bbc50)
	/Users/nick/dev/gopath/pkg/mod/github.com/sourcegraph/[email protected]/check.go:166 +0x5e
github.com/sourcegraph/docsite.walkHTMLDocument(0xc002d58310, 0xc0009bbc50)
	/Users/nick/dev/gopath/pkg/mod/github.com/sourcegraph/[email protected]/check.go:166 +0x5e
github.com/sourcegraph/docsite.walkHTMLDocument(0xc002d356c0, 0xc0009bbc50)
	/Users/nick/dev/gopath/pkg/mod/github.com/sourcegraph/[email protected]/check.go:166 +0x5e
github.com/sourcegraph/docsite.walkHTMLDocument(0xc002b6b7a0, 0xc0009bbc50)
	/Users/nick/dev/gopath/pkg/mod/github.com/sourcegraph/[email protected]/check.go:166 +0x5e
github.com/sourcegraph/docsite.walkHTMLDocument(0xc002b6b030, 0xc0009bbc50)
	/Users/nick/dev/gopath/pkg/mod/github.com/sourcegraph/[email protected]/check.go:166 +0x5e
github.com/sourcegraph/docsite.walkHTMLDocument(0xc002b6afc0, 0xc0009bbc50)
	/Users/nick/dev/gopath/pkg/mod/github.com/sourcegraph/[email protected]/check.go:166 +0x5e
github.com/sourcegraph/docsite.(*Site).checkContentPage(0xc00044cf00, 0xc002d300c0, 0xc0033c5600, 0x11, 0x20)
	/Users/nick/dev/gopath/pkg/mod/github.com/sourcegraph/[email protected]/check.go:115 +0x123
github.com/sourcegraph/docsite.(*Site).Check(0xc00044cf00, 0x1888900, 0xc0000b6000, 0x0, 0x0, 0x0, 0x100d3b9, 0x1d11dc0, 0x1eafd98, 0x0)
	/Users/nick/dev/gopath/pkg/mod/github.com/sourcegraph/[email protected]/check.go:50 +0x704
main.init.0.func1(0xc0000b2010, 0x0, 0x0, 0x0, 0x0)
	/Users/nick/dev/gopath/pkg/mod/github.com/sourcegraph/[email protected]/cmd/docsite/check.go:21 +0xb8
main.commander.run(0xc000228170, 0x2, 0x2, 0xc00036a120, 0x16e64e3, 0x7, 0xc00002f2c0, 0xc0000b2010, 0x1, 0x1)
	/Users/nick/dev/gopath/pkg/mod/github.com/sourcegraph/[email protected]/cmd/docsite/cmd.go:117 +0x301
main.main()
	/Users/nick/dev/gopath/pkg/mod/github.com/sourcegraph/[email protected]/cmd/docsite/main.go:46 +0xee

Errors found in Markdown documentation files. Fix the errors in doc/ and try again.

I deduced the problem and fixed with this commit:
sourcegraph/sourcegraph@0f6184b

Support redirects

It should be possible to tell docsite that a certain path /foo should redirect to another path /bar. This would make it easier to rename documents without leaving a stub doc at the old path that mentions the new path.

Logging bug in the BlackFriday markdown engine re:emphasizing underscore link paths (we can't fix directly; filing for documentation purposes)

Logging a known bug on the BlackFriday markdown renderer that I ran into with this handbook PR

We can't fix this directly, but I'm logging here to note:

  • This is known, in case someone else comes looking for it
  • If a lot of bugs start to pop up with Black Friday, it might be worth looking at using a different library (I don't think we're at that point, but these are the data points we'd want if we had to make that decision someday). A related point to this looked like #25

Newlines are no longer rendered as a space

A newline in a .md file is no longer rendered as a space, leading to unintentionally joined words:

image

Whereas in the source .md file it is typed like this:

Sourcegraph makes our best effort to use the least amount of calls to your code host. However, it is possible for Sourcegraph 
to encounter rate limits in some scenarios. Please see the specific code host documentation for more information and how to 
mitigate these issues. 

This seems to be a regression. Not sure if there's an easy configuration for this in Goldmark

Support versions with "/"

If the version is backed by a Git revspec, then it needs to be able to contain multiple path components.

Add Google Analytics event tracking to install script under QuickStart guide

We are currently tracking the event/goal in Google Analytics (GA) of how many people copy the install script from the Getting Started page on the About website (https://about.sourcegraph.com/get-started). The goal/event is set to trigger when someone clicks on the blue clipboard copy icon in the upper right corner of the box with the Docker script. We'd like to add the same clipboard/copy icon and do the same tracking in GA of the Docker install script that appears at the top of the Docs homepage, under the QuickStart guide (https://docs.sourcegraph.com/). According to Aileen, this requires a small piece of code that does an onClick event over the copy/install button, and that may be a challenge since it's in markdown and applied to a typescript template.

Use release versions to tag docsite containers additionally to using the latest tag

Presently, images are only tagged with latest. Also, when deploying docs.sourcegraph.com, we ensure that we're fetching the correct one with the digest.

The problem is that when we release a new version of docsite, the present process requires to override the latest tag, therefore breaking the ability to deploy the previous version if the docker daemon doesn't have it cached locally.

That's probably fine most of the time, but it could still happen.

So we could:

  1. Keep the latest tag as it is
  2. Tag and push on new releases, i.e v1.8.2 and latest
  3. Automate image building and pushing in Github Actions

Which would enable us to use the tagged version in our deployment manifests.

Feature request: Embed snippets

Use case

All Sourcegraph extension tutorials currently have the same set up steps and for now, the same content must be copied and pasted into each.

Being able to embed a snippet would fix this, ensuring the set up content is the same for all tutorials.

If a header is itself a link, clicking on that header on the sidebar will go to the link URL, not jump to the header

This one is complicated to explain... A simple example will help:

On the org chart page, there are two headers at the top: "Engineering" and "Campaigns". The first one is just a header, not a link, while the second is itself a link.

image

Over on the right is a sidebar with the page's table of contents. If you click on the sidebar link to "Engineering", it will jump you to that header on the same page:

image

See how it adds #engineering to the URL and jumps me there:

image

If I click on the "campaigns" link on the sidebar, however, it jumps me to the URL that the header itself links to. I.e., to the campaigns page itself:

image

This seems inconsistent.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.