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

Custom Themes: Default theme not being inherited #2490

Closed
Ehesp opened this issue Jan 27, 2024 · 2 comments
Closed

Custom Themes: Default theme not being inherited #2490

Ehesp opened this issue Jan 27, 2024 · 2 comments
Labels
question Question about functionality

Comments

@Ehesp
Copy link

Ehesp commented Jan 27, 2024

Hello

I'm trying to modify the default theme. I've got a directory alongside my application which contains the theme, so I'm importing the distributed files as a plugin, then applying the theme, e.g:

typedoc --plugin ./my-theme --theme custom

The code for my theme is pretty simple, and follows the docs here: https://github.com/TypeStrong/typedoc/blob/master/internal-docs/custom-themes.md

The code (modified, as I think those are slightly out of date):

class MyThemeContext extends DefaultThemeRenderContext {
   // ...
}

class MyTheme extends DefaultTheme {
    private _contextCache?: MyThemeContext;
    override getRenderContext(page) {
        this._contextCache ||= new MyThemeContext(
            this, // <-- changed
			page, // <-- added
            this.application.options,
        );
        return this._contextCache;
    }
}

export function load(app: Application) {
    app.renderer.defineTheme("custom", MyTheme);
}

I kind of expected the theme in this case to be exactly the same as the default one, where I could then override specific parts such as the footer.. However instead the generated docs contain none of the sub-pages (classes, interfaces etc) and no CSS styles.

Is this expected?

@Ehesp Ehesp added the question Question about functionality label Jan 27, 2024
Gerrit0 added a commit that referenced this issue Jan 27, 2024
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jan 27, 2024

Oops, apparently I completely forgot to update that, thanks for pointing it out!

Your intuition is correct for how that ought to work. I have a couple questions:

  1. Are you getting a warning that says this?

    TypeDoc has been loaded multiple times. This is commonly caused by plugins which have their own installation of TypeDoc

    If so, then your theme is likely importing a different installation. This is a problem because TypeDoc relies on instanceof checks when determining whether to do some things (like copy CSS to the output directory). This is generally the most obvious place where things get broken, but there are tricky cases that aren't obvious too. The only reason it isn't an error is because for plugin development there are truly some cases where it doesn't matter.

  2. Are the docs not containing sub pages, or are you not getting links to them in the sidebar? The generated JS for the sidebar is also guarded by an instanceof check. If the pages themselves aren't getting generated, that's odd...

@Ehesp
Copy link
Author

Ehesp commented Jan 28, 2024

Ahh thanks that was the issue, should have been obvious by the error.

Appreciate your time.

@Ehesp Ehesp closed this as completed Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about functionality
Projects
None yet
Development

No branches or pull requests

2 participants