-
Notifications
You must be signed in to change notification settings - Fork 182
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
Directory structure improvements #328
Comments
Hi - thanks. It is not quite a breadcrumb, - more of a module tree helper - but I take your point. It kind of begs the question what is the point of that line at all. I will review it as looking to make some other ui enhancements (other suggestions welcome :)). |
Thank you very much! I have a lot of other suggestions actually. :) Biggest thing for me is I want to be able to specify the title of the page and the nested location, but maybe that belongs in a separate issue. |
Do you have an example of what you might expect? |
Hi Tom, Gladly. 😊 Imagine that we have a basic TypeScript library that provides some helper functions for fruit. It has helper functions for:
It also exposes a enum FruitType {
Apple,
Banana,
PassionFruit,
} So, the file structure of our TypeScipt project would look like this:
Now, we want to generate some API documentation automatically for the project. The obvious choice is to use TypeDoc. Of course, we also want to use your awesome However, when we execute
This is no good. Helpfully, the Instead, we want to have a separate Docusaurus page for apples, bananas, and passion fruit. So, let's try invoking TypeDoc by specifying all of the entry points specifically: npx typedoc \
--plugin typedoc-plugin-markdown \
--entryPoints src/functions/apples.ts \
--entryPoints src/functions/bananas.ts \
--entryPoints src/functions/passionFruit.ts \
--entryPoints src/enums/FruitType.ts \ We get the following output:
Much better! But some problems remain. Problem 1 - SectionsIn our example project, we want there to be two different sections on the Docusaurus left-hand side bar:
These will correspond to the source directories of "src/functions" and "src/enums", respectively. However, we don't want to maintain a manual mapping of source files --> Docusaurus sidebar locations. That's going to be hard to maintain and will get out of date. Instead, Docusaurus has a helpful feature where it will automatically make a sidebar that corresponds to an input file system. You enable this with However, a problem: TypeDoc messed up the folder structure. In other words, we started with:
And we ended up with:
But what we really want is for TypeDoc to respect the structure and for it to generate a Markdown file like this:
Feature request 1: But of course, that might not make sense for all TypeScript projects. What we really want is to give the end-user control as to where the generated Markdown files should go. Feature request 2: /**
* This is a collection of helper functions regarding passion fruit.
*
* @module
* @path functions/arbitrarySubDirectory/passionFruit.md
*/
/** This is the documentation for my "usePassionFruit" helper function. Blah blah blah. */
function usePassionFruit() {} Problem 2 - Markdown TitlesAt the top of every Markdown file, there are breadcrumbs - but that's easy enough to disable with the helpful Once we've done that, the first line of the "functions_passionFruit.md" becomes: # Module: functions/passionFruit Here, the word "Module" is superfluous. In our project, every individual Docusaurus page is going to be a module. So, we can get rid of the "Module: " prefix. Additionally, the "functions/" is superfluous, because it can already be seen from the left-hand sidebar that we are in the category of "Functions". So, we can also get rid of the "functions/" prefix. But even having a title of In this trivial example, we might want TypeDoc already exposes a feature to rename a module: the
This works great. The resulting markdown file name becomes:
And the Markdown title becomes: # Module: Passion Fruit (Argentinian) So all that's needed is for the plugin to remove the "Module: " prefix. Feature request 3: Remove the "Module: " prefix in the title, either always, or only when the "@module" name is specified. However, even if the "Module: " prefix was removed, we still wouldn't be able to use the "@module" feature without a fix for problem 1 above. This is because we've lost the meta-data along the way that specifies that this is a Markdown file that belongs in the "Functions" section of the sidebar. Thus, in order for modules to have arbitrary names, it's essential that we have feature request 1/2 above. Problem 3 - DuplicationYet another issue in our Docusaurus website has to do with our Notice that in our generated output, there are two separate pages that were generated for
The first page contains all the "real" information about the enum, such as the values for all the enum members. The second page is just a stub that has a link to the first page, with nothing else of interest. Having the second page be generated at all is a bug. We just want to have the first file be in the "Enums" part of the left-hand side bar, and that's it. Feature request 3: This can be stated more generically: Consider the case where I have a module entry point with a few functions, and a few tiny interfaces. In this scenario, TypeDoc would automatically put the interfaces on separate pages. That's bad, because the interfaces / types aren't big enough to warrant putting them on their own dedicated pages. And it makes it harder for end-users to understand what the functions are doing, as they are now warping back and forth between entirely different pages. The end-user should have control of this. If it would be useful for interfaces/types/enums/classes to be own their own Docusaurus pages, then the end-user should put them in a dedicated entry-point. Easy! |
Thanks for detailing this very useful. There is also some history with this in #317. I am currently refactoring quite a lot of things (removing handlebars, making it easy to implement custom theme etc) with a bunch of other stuff haven't had time to fix - so will look at addressing with the next major version. Problem 1 - Sections
Problem 2 - Markdown Titles
The titles were defined in this way to follow the html theme but agree not needed. Also with next version it should be easy to to override the title component with a custom component in whatever format is required. Problem 3 - Duplication
Agreed that there should be a mechanism to keep all symbols of a module in a single page. Have been looking at it. |
Tom, thanks for the quick reply.
This seems like a really useful option for some use-cases. However, for our basic fruit library, it doesn't help us. When we turn on the option here, it puts each individual helper function on its own Docusaurus page. This isn't what we want - we will have thousands of individual helper functions, and this will result in a left-hand sidebar that will be impossible to navigate. We need to keep the structure outlined previously: an "autogenerated" Docusaurus sidebar, with "sections" corresponding to directories, and one page per file/module (not one page per reflection). |
We might be able to piggy-back off of the "@category" tag, but I don't think it is a very good idea. Correct me if I am wrong, but the tag seems to be meant to go on individual exports, not a top-level module JSDoc comment. For example, in our fruit library, say that for some reason, we wanted to refactor the "apple.ts", "banana.ts", and "passionFruit.ts" functions together into a combined "functions.ts". If we did that, it might still be possible to still get the same Docusaurus output as before, because we could manually annotate In this context, "@category" is a shorthand for "this is the module that I want the function to belong to". But this concept doesn't quite map on to what we want to do at a module-level. We don't need to specify which module that a module belongs to. That doesn't make any sense - it's already a module, and it doesn't belong to any other modules. Rather, we want to specify where the module is going to live on the file system. |
Ok been making some progress on In this case we have exported 2 modules, enums and functions with their own distinct directories. Within the function module we are exporting apples, bananas and passionfruit modules. You may be wondering why enums.md is neccessary, but each module does need an entry point when there is no navigation. But we could hoist all symbols from in a module in one file. I will carry on playing around but any input would be great. Have a look at the example project and feel free to add some further use cases in there with an MR. Here is the directory structure: |
Hell yeah, looking fantastic so far! Some small tweaks are needed, I think we need to add Also, what does Also, for the apples function page, the Markdown title is "# apples" instead of "# Apples", so it looks like we need to add "@module Apples" to the JSDoc comment for the file I presume. I tried to clone the repo and build it like this: git clone git@github.com:tgreyuk/typedoc-plugin-markdown.git
cd typedoc-plugin-markdown
git checkout next
yarn
cd examples/fruit-api
npx typedoc But I got a bunch of errors:
Not sure what to do from here. |
update the branch and then run the docs script (instead of npx typedoc):
basically need to build the package locally first.
https://typedoc.org/guides/options/#githubpages I am going to continue looking at output - feel free to add some code samples to play around with. |
I tried today, and its still broken. Steps to reproduce: git clone git@github.com:tgreyuk/typedoc-plugin-markdown.git
cd typedoc-plugin-markdown
git checkout next
yarn
cd examples/fruit-api
yarn run docs
yarn run docs The first |
In our current fruit API, we are exporting by name, like this:
|
Another problem: It looks like the TypeDoc plugin isn't respecting the In other words, if we put the following at the top of /**
* This is the documentation for passion fruit functions.
*
* @module Passion Fruit
*/ Then the first line of the resulting |
Another thing: In the current setup, TypeDoc creates index files like "functions.md". But these won't be needed for us, because we will be able to see all of the functions easily using the Docusaurus left sidebar. Furthermore, generating all of these "index" files results in a buggy-looking Docusaurus sidebar with duplicated items like this: So how about a plugin option called "makeModuleIndexes". If set to false, then the plugin would automatically delete files like "functions.md" for us, so that they don't clutter the output. |
Is your project on a public repo - it would be good to test against a real project. |
More bugs: The source code looks like this: import { CornerType } from "../enums/CornerType";
export interface Corner {
readonly type: CornerType;
readonly position: Readonly<Vector>;
} So it has 2 fields, but for some reason neither of them are documented. Edit - you can see it in the Fruit API too, the enum members of |
Tom, Any progress on this? I'm eagerly awaiting the leveled-up version of the plugin. |
Hello,
In my TypeScript project, I have a class called
DefaultMap
.When I use Typedoc +
typedoc-plugin-markdown
with thehideBreadcrumbs
value set tofalse
, it generates the following output:When I use Typedoc +
typedoc-plugin-markdown
with thehideBreadcrumbs
value set totrue
, it generates the following output:Here, we can see that the plugin removed the first "breadcrumb" line, but it did not remove the link to the parent module on the 5th line. Is this not defined as a "breadcrumb"? Shouldn't the plugin also be removing this line? It seems to me that if the end-user wants breadcrumb lines to be removed, it should also be removing this line.
This same behavior seems to apply to interfaces and enums in addition to classes.
The text was updated successfully, but these errors were encountered: