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

feat: Expose relative path in PageMetaData #161

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ yarn compile

## Ember

```
```bash
cd packages/ember
yarn start
```

## Core

```bash
cd packages/core
# yarn test --watch for watch mode
yarn test
```
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class Docfy {
title,
editUrl,
relativeUrl: undefined,
relativePath,
headings: [],
frontmatter: frontmatter,
pluginData: {},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Heading {
export interface PageMetadata {
url: string;
relativeUrl: undefined | string;
relativePath: string;
editUrl: string;
title: string;
headings: Heading[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Object {
"headings": Array [],
"parentLabel": "components",
"pluginData": Object {},
"relativePath": "packages/package1/components/button.md",
"relativeUrl": "button",
"title": "Button Component",
"url": "/docs/category1/components/button",
Expand All @@ -36,6 +37,7 @@ Object {
"headings": Array [],
"parentLabel": "components",
"pluginData": Object {},
"relativePath": "packages/package1/components/form/index.md",
"relativeUrl": "form",
"title": "Form Component",
"url": "/docs/category1/components/form",
Expand All @@ -50,6 +52,7 @@ Object {
"headings": Array [],
"parentLabel": "components",
"pluginData": Object {},
"relativePath": "packages/package1/components/form/something-else.md",
"relativeUrl": "something-else",
"title": "something-else",
"url": "/docs/category1/components/something-else",
Expand All @@ -68,6 +71,7 @@ Object {
"headings": Array [],
"parentLabel": "category1",
"pluginData": Object {},
"relativePath": "packages/package1/docs/intro.md",
"relativeUrl": "intro",
"title": "Docs Intro",
"url": "/docs/category1/intro",
Expand All @@ -89,6 +93,7 @@ Object {
"headings": Array [],
"parentLabel": "category2",
"pluginData": Object {},
"relativePath": "packages/package2/docs/overview.md",
"relativeUrl": "overview",
"title": "Overview",
"url": "/docs/category2/overview",
Expand All @@ -102,6 +107,7 @@ Object {
"headings": Array [],
"parentLabel": "category2",
"pluginData": Object {},
"relativePath": "packages/package2/docs/styles.md",
"relativeUrl": "styles",
"title": "How styles work",
"url": "/docs/category2/styles",
Expand All @@ -121,6 +127,7 @@ Object {
"headings": Array [],
"parentLabel": "test-custom",
"pluginData": Object {},
"relativePath": "docs/custom-url.md",
"relativeUrl": "url",
"title": "This a test for the ability to change the url using frontmatter",
"url": "/docs/test-custom/url",
Expand All @@ -139,6 +146,7 @@ Object {
"headings": Array [],
"parentLabel": "docs",
"pluginData": Object {},
"relativePath": "README.md",
"relativeUrl": "",
"title": "The index",
"url": "/docs/",
Expand All @@ -151,6 +159,7 @@ Object {
"headings": Array [],
"parentLabel": "docs",
"pluginData": Object {},
"relativePath": "docs/how-it-works.md",
"relativeUrl": "how-it-works",
"title": "How it works?",
"url": "/docs/how-it-works",
Expand Down Expand Up @@ -184,6 +193,7 @@ Object {
],
"parentLabel": "docs",
"pluginData": Object {},
"relativePath": "docs/about.md",
"relativeUrl": "about",
"title": "About the project",
"url": "/docs/about",
Expand All @@ -194,6 +204,7 @@ Object {
"headings": Array [],
"parentLabel": "docs",
"pluginData": Object {},
"relativePath": "docs/html.md",
"relativeUrl": "html",
"title": "HTML should work",
"url": "/docs/html",
Expand All @@ -204,6 +215,7 @@ Object {
"headings": Array [],
"parentLabel": "docs",
"pluginData": Object {},
"relativePath": "docs/math.md",
"relativeUrl": "math",
"title": "Testing math remark and rehype plugins",
"url": "/docs/math",
Expand All @@ -214,6 +226,7 @@ Object {
"headings": Array [],
"parentLabel": "docs",
"pluginData": Object {},
"relativePath": "docs/static-asset.md",
"relativeUrl": "static-asset",
"title": "This is a markdown that has a image",
"url": "/docs/static-asset",
Expand All @@ -224,6 +237,7 @@ Object {
"headings": Array [],
"parentLabel": "docs",
"pluginData": Object {},
"relativePath": "docs/table.md",
"relativeUrl": "table",
"title": "Table example",
"url": "/docs/table",
Expand Down
32 changes: 32 additions & 0 deletions packages/ember/docs/components/docfy-output-demo/edit-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,35 @@ repository URL as well as the branch to edit.
{{/if}}
</DocfyOutput>
```

For this to work, you need to include `repository` in your docfy-config:

```js
// in your docfy-config.js
module.exports = {
repository: {
url: 'https://github.com/@username/repo-name',
editBranch: 'main',
},
...// rest of your config
}
```


## Enterprise (aka on premise) git services

`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:

```hbs
<DocfyOutput @fromCurrentURL={{true}} as |page|>
{{#if page.relativePath}}
<a href=(concat "http://some-enterpise.com/browse/" page.relativePath)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: the build breaks if I use hbs template instead of just hbs...not sure why?

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.