Skip to content
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

Use absolute URL's for the assets #940

Closed
jeffreymeng opened this issue Jan 8, 2019 · 15 comments
Closed

Use absolute URL's for the assets #940

jeffreymeng opened this issue Jan 8, 2019 · 15 comments
Labels
enhancement Improved functionality
Milestone

Comments

@jeffreymeng
Copy link

jeffreymeng commented Jan 8, 2019

I want to be able to use clean URLs with trailing slashes for the links in my generated docs (e.g. page.html becomes /page/), however all the references to the assets are relative, so they all break when using clean URLs with a trailing slash.

Is there any way to make the links to the assets relative (I provide a base path)?

@Gerrit0 Gerrit0 added the enhancement Improved functionality label Jan 9, 2019
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jan 9, 2019

This isn't possible right now with the default theme, but it would be a neat feature to have.

@RohitRox
Copy link

RohitRox commented Aug 9, 2019

Momentarily I am doing this bad hack in typedoc.js to get base path/url prefix

  const Handlebars = require('handlebars');

  const BASE_URL="https://some.app/";

  Handlebars.registerHelper('relativeURL', function(url) {
    return BASE_URL + url;
  });

  module.exports = {
  // typedoc configs
  }

@DavidPeicho
Copy link

DavidPeicho commented Apr 1, 2020

I went for another hack. It's broken only for the index.html page. There are not many links, so this should be good enough:

sed -re 's@<(\w+)(.*)href="([^http].*)"(.*)>@<\1\2href="/api\/\3"\4>@g' -i ./dist/api/index.html
sed -re 's@"(assets/.+)"@"/api/\1"@g' -i ./dist/api/index.html

Basically I use the sed utility to create my own path relative to a subroute api.
I am sure my regexp isn't 100% reliable, but for this use case it should be good enough.

To explain a bit more:
The first sed will look for tag like <link> and <a>, extract their href when they don't start with the letters "http", and I then prepend to the href my subroute (in this case api).

The second one works the same way but search for every "assets/" (for script, search, etc...)

@weibinzhu
Copy link

weibinzhu commented Jun 29, 2021

Momentarily I am doing this bad hack in typedoc.js to get base path/url prefix

  const Handlebars = require('handlebars');

  const BASE_URL="https://some.app/";

  Handlebars.registerHelper('relativeURL', function(url) {
    return BASE_URL + url;
  });

  module.exports = {
  // typedoc configs
  }

@RohitRox sorry to bother, but could you explain more? Because I tried to config in the same way but didn't work.

@weibinzhu
Copy link

Momentarily I am doing this bad hack in typedoc.js to get base path/url prefix

  const Handlebars = require('handlebars');

  const BASE_URL="https://some.app/";

  Handlebars.registerHelper('relativeURL', function(url) {
    return BASE_URL + url;
  });

  module.exports = {
  // typedoc configs
  }

@RohitRox sorry to bother, but could you explain more? Because I tried to config in the same way but didn't work.

I get it. Basically I need to overwrite the custom helper "relativeURL" initally defined in typedoc, to do that I need to register another one and make sure that both typedoc and my own project are using the same Handlebars.

@marcin-wlodarczyk
Copy link

marcin-wlodarczyk commented Aug 11, 2021

+1

There should be absoluteUrl cli option available.

@zhixinbao
Copy link

+1

@chrisui
Copy link

chrisui commented Dec 10, 2021

Slightly confused how this works in the actual typedoc website where generated docs are hosted at /example and /api? Links throughout the docs are all generated relative to those. Ie. /example/assets/main.js

edit: ah, trailing slash is important. I was using next.js as a proxy for the generated output which strips trailing slashes by default.

@aminya
Copy link

aminya commented Dec 6, 2022

GitHub Pages doesn't work with relative paths. This option is necessary.
https://www.pluralsight.com/guides/fixing-broken-relative-links-on-github-pages

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Dec 6, 2022

GitHub Pages doesn't work with relative paths.

Given that TypeDoc's site, which includes two rendered TypeDoc projects, is deployed to GH pages with no issues I'm pretty confident in saying this is false...

@aminya
Copy link

aminya commented Dec 6, 2022

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Dec 6, 2022

The site you linked to is built with an ancient version of TypeDoc... which isn't even TypeDoc, it's an unmaintained fork. The problem you're running into is not relative links, but that the githubPages option was added in 0.22.4. Prior to that, if deploying to GitHub pages, you had to manually create a .nojekyll file in your deployed directory to prevent GitHub pages from removing files starting with _ from your deployed site.

@aminya
Copy link

aminya commented Dec 7, 2022

OK, updating the typedoc fixes that issue. I missed the package renaming and npm-check-updates didn't update beyond that version.

@isaacyakl
Copy link

isaacyakl commented Jan 4, 2023

Slightly confused how this works in the actual typedoc website where generated docs are hosted at /example and /api? Links throughout the docs are all generated relative to those. Ie. /example/assets/main.js

edit: ah, trailing slash is important. I was using next.js as a proxy for the generated output which strips trailing slashes by default.

I was in the same situation (deploying to a subdirectory in Vercel: /public/docs). As @chrisui stated, link to your TypeDoc documentation directory with a trailing slash until this issue is resolved or an option is provided.

Do NOT do this:

example.com/docs

Do this:

example.com/docs/

@Gerrit0 Gerrit0 added this to the v0.26.0 milestone Oct 15, 2023
@Gerrit0 Gerrit0 modified the milestones: v0.27.0, v0.26.0 Jun 1, 2024
@Gerrit0 Gerrit0 mentioned this issue Jun 1, 2024
7 tasks
Gerrit0 added a commit that referenced this issue Jun 9, 2024
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jun 16, 2024

An option --useHostedBaseUrlForAbsoluteLinks is included in TypeDoc 0.26, which is releasing 2024/06/21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improved functionality
Projects
None yet
Development

No branches or pull requests

10 participants