This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
forked from gravitational/teleport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow more paths in partial link resolution (gravitational#180)
Fixes gravitational#167 `handlePartialLink` currently hardcodes `docs/pages` as the location of all docs pages, and uses this file path segment to construct the absolute path of the MDX file that includes a partial. This change adds the root directory of all partials as a parameter of `handlePartialLink` and uses that instead. Since this root directory is configurable outside `remark-includes`, this change lets us add unit tests for `handlePartialLink`. This change also handles relative path resolution for image and link definition URLs. The current version of `handlePartialLink` only handles links paths. As a result, this renames `handlePartialLink` to `handleURLPath`.
- Loading branch information
Showing
5 changed files
with
160 additions
and
12 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
server/fixtures/includes/database-access/attach-iam-policies.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Attach the policy and permission boundary you created earlier to the IAM | ||
identity your Teleport Database Service will be using. | ||
|
||
For example, if the Database Service runs as an IAM user, go to the page of the IAM user | ||
in the AWS Management Console, attach the created policy in the "Permissions | ||
policies" section, and set the created boundary policy in the "Permissions | ||
boundary" section. | ||
|
||
<Figure> | ||
![IAM user](../../../img/database-access/[email protected]) | ||
</Figure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
Check out our [instructions](../installation.mdx). | ||
|
||
Here is an image showing a successful installation: | ||
|
||
[Successful installation](../installation.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This partial has a relative link [definition]. | ||
|
||
[definition]: ../../installation.mdx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -483,4 +483,111 @@ Suite("Resolves template variables in includes", () => { | |
assert.equal(result, expected); | ||
}); | ||
|
||
Suite( | ||
"Resolves relative links in partials based on the path of the partial", | ||
() => { | ||
const includingRelativeLink = `Here are instructions on installing the software: | ||
(!include-relative-link.mdx!) | ||
`; | ||
interface testCase { | ||
includingPage: string; | ||
description: string; | ||
path: string; | ||
expected: string; | ||
} | ||
const testCases: testCase[] = [ | ||
{ | ||
includingPage: includingRelativeLink, | ||
description: "including file is on the same dir level as the partial", | ||
path: "server/fixtures/dir/samelevel.mdx", | ||
expected: `Here are instructions on installing the software: | ||
Check out our [instructions](../installation.mdx). | ||
Here is an image showing a successful installation: | ||
[Successful installation](../installation.png) | ||
`, | ||
}, | ||
{ | ||
includingPage: includingRelativeLink, | ||
description: "including file is below the dir level of the partial", | ||
path: "server/fixtures/dir/dir2/below.mdx", | ||
expected: `Here are instructions on installing the software: | ||
Check out our [instructions](../../installation.mdx). | ||
Here is an image showing a successful installation: | ||
[Successful installation](../../installation.png) | ||
`, | ||
}, | ||
{ | ||
includingPage: includingRelativeLink, | ||
description: "including file is above the dir level of the partial", | ||
path: "server/fixtures/above.mdx", | ||
expected: `Here are instructions on installing the software: | ||
Check out our [instructions](installation.mdx). | ||
Here is an image showing a successful installation: | ||
[Successful installation](installation.png) | ||
`, | ||
}, | ||
{ | ||
includingPage: `Here's how to attach an IAM policy for DB Access: | ||
(!database-access/attach-iam-policies.mdx!) | ||
`, | ||
description: "relative image path", | ||
path: "server/fixtures/includes/db-policy.mdx", | ||
expected: `Here's how to attach an IAM policy for DB Access: | ||
Attach the policy and permission boundary you created earlier to the IAM | ||
identity your Teleport Database Service will be using. | ||
For example, if the Database Service runs as an IAM user, go to the page of the IAM user | ||
in the AWS Management Console, attach the created policy in the "Permissions | ||
policies" section, and set the created boundary policy in the "Permissions | ||
boundary" section. | ||
<Figure> | ||
![IAM user](../../img/database-access/[email protected]) | ||
</Figure> | ||
`, | ||
}, | ||
{ | ||
includingPage: "(!includes-relative-link-def.mdx!)", | ||
description: "relative definition path", | ||
path: "server/fixtures/definition.mdx", | ||
expected: `This partial has a relative link [definition]. | ||
[definition]: ../installation.mdx | ||
`, | ||
}, | ||
]; | ||
|
||
for (const testCase of testCases) { | ||
const actual = transformer({ | ||
value: testCase.includingPage, | ||
path: testCase.path, | ||
}).toString(); | ||
|
||
assert.equal( | ||
actual, | ||
testCase.expected, | ||
new Error( | ||
`${testCase.description}: expected the output:\n` + | ||
testCase.expected + | ||
"\n\n" + | ||
"but got:\n" + | ||
actual | ||
) | ||
); | ||
} | ||
} | ||
); | ||
|
||
Suite.run(); |