Skip to content

Commit

Permalink
Merge pull request #161 from nicolechung/expose_relative_path
Browse files Browse the repository at this point in the history
feat: Expose relative path in PageMetaData
  • Loading branch information
josemarluedke authored Jul 19, 2023
2 parents 3745bd3 + 2866085 commit 5408b1d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
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)
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.

0 comments on commit 5408b1d

Please sign in to comment.