This component exposes some of the result data from the build that you can use to render, for example, a sidebar navigation, "on this page" section, and more.
Depending on the arguments you pass to the component, the output could be one of the following values:
NestedPageMetadata
PageMetadata[]
PageMetadata
undefined
To learn more about each data type, please refer to the API docs.
Below you can see several examples of what is possible to build using this component.
In this example, we are using the option @fromCurrentURL
. It tells the component
to search for the definition of the page that corresponds to the current URL.
We are then using the headings
property, a data structure that represents a
Table of Content. The headings
is a recursive data structure, meaning that you
can render their child for subheadings and their sub-subheadings. The depth of
headings available here is default to 6 but can be changed using the configuration
option tocMaxDepth
.
<DocfyOutput @fromCurrentURL={{true}} as |page|>
<div class="mb-4 font-medium">
On this page:
</div>
<ul class="list-disc list-inside space-y-2">
{{#each page.headings as |heading|}}
<li>
<a href="#{{heading.id}}">
{{heading.title}}
</a>
</li>
{{/each}}
</ul>
</DocfyOutput>
This is another example using @fromCurrentURL
, but here we build a "edit this
page" link.
For this feature to work, Docfy must be able to find the repository URL. In
Ember apps, we extract that from the package.json
, but you can configure the
repository URL as well as the branch to edit.
For this to work, you need to include repository
in your docfy-config:
// in your docfy-config.js
module.exports = {
repository: {
url: 'https://github.com/@username/repo-name',
editBranch: 'main',
},
...// rest of your config
}
page.editUrl
works for Github, Bitbucket, Gitlab and Sourcehut.
For on-premise instances git solutions (i.e. on-premise Gitlab, or on-premise Bitbucket), we expose the page.relativePath
so that you might construct your own custom editUrl:
<DocfyOutput @fromCurrentURL={{true}} as |page|>
{{#if page.relativePath}}
<a href=(concat "http://some-enterpise.com/browse/" page.relativePath)
Click here to edit this page
</a>
{{/if}}
</DocfyOutput>
Note: the edit url for your on-premise instance might be more complex than the example above. But the page.relativePath
will give you the relative path to that file in your repo.
<DocfyOutput @fromCurrentURL={{true}} as |page|>
{{#if page.editUrl}}
<a href={{page.editUrl}}>
Click here to edit this page
</a>
{{/if}}
</DocfyOutput>
This option will return an array of PageMetadata
. It will contain all the
pages in a flat array, one could render a list of all the pages without worrying
about the scope.
<DocfyOutput @type="flat" as |pages|>
<ul class="list-disc list-inside space-y-2">
{{#each pages as |page|}}
<li>
<DocfyLink @to={{page.url}}>
{{page.title}}
</DocfyLink>
</li>
{{/each}}
</ul>
</DocfyOutput>
This component has a few different options that are used to filter what the returning value should be. Here is the arguments this component accepts.
Argument | Description | Type | Default Value |
---|---|---|---|
@type |
If the result should be a flat list or nested | 'flat' | 'nested' |
'nested' |
@fromCurrentURL |
If the result should be filtered from the current URL | boolean | undefined |
|
@url |
Find the page definition for the given URL | string | undefined |
|
@scope |
If the result should be filtered by an scope name | string | undefined |