Skip to content

Remove <base href /> and relative hrefs #2090

Closed
@jdkoren

Description

@jdkoren

Context

Currently DartDoc emits relative hrefs when linking to another generated page. These hrefs all start from the docs output directory. In order to make these work, each page also includes a <base href /> in the <head> that walks back to the docs output directory (i.e. .. or ../..). For example, consider these sources:

library a;

class Foo {
  void hello(Bar bar) { /* ... */ }
}

library b;

class Bar { /* ... */ }

The docs tree would partially look like this:

api/docs/
├── a/
│   ├── a-library.html
│   ├── Foo/
│   │   └── hello-method.class
│   └── Foo-class.html
└── b/
    ├── b-library.html
    └── Bar-class.html

In a/Foo-class.html DartDoc emits <base href=".." />, and emits links to Bar in the form of <a href="b/Bar-class.html" />. Such links will be resolved properly as
{api/docs}/a/../b/Bar-class.html => {api/docs}/b/Bar-class.html.
Without the <base href>, the link would go to a nonexistent page: {api/docs}/a/b/Bar-class.html.

While this technique does make the pages quite portable, we can't use it for Markdown output (#1479). Also, there may be hosting situations where this <base href /> isn't ideal or can't be used.

Proposal: absolute hrefs from site root

The current hrefs are already relative to the site root and can be made absolute by placing a / in front: <a href="/b/Bar-class.html" />. Assuming the site root is in fact api/docs/ in our example, these links will always resolve properly. #2089 implements this.

Caveats and concerns

Specifying a site root

Using a different site root requires updating all the generated hrefs. DartDoc could support a site root prefix to hrefs via a new DartdocOption, otherwise clients are left to using a separate process to find and replace the hrefs. This option is under consideration and not yet implemented.

Link validation

DartDoc tries to ensure that generated links lead to valid pages. This process needs to account for the new href format and any new options for a site root prefix.

Transitioning important DartDoc usages

Major users of DartDoc include api.dartlang.org and flutter.dev/api. These and other usages need to be transitioned smoothly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1A high priority bug; for example, a single project is unusable or has many test failurescustomer-flutterIssues originating from important to Fluttercustomer-google3Issues originating from or important to Angulartype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions