Skip to content

Commit 5122ea8

Browse files
committed
chore: add docs & tests for link-text for headlines
1 parent 3032ba9 commit 5122ea8

File tree

5 files changed

+115
-5
lines changed

5 files changed

+115
-5
lines changed

packages/engine/test-node/05z-menu.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,4 +893,40 @@ describe('Engine menus', () => {
893893
url: '/',
894894
});
895895
});
896+
897+
it('15: link-text attribute', async () => {
898+
const { build, readSource } = await setupTestEngine(
899+
'fixtures/05-menu/16-link-text-attribute/docs',
900+
);
901+
await build();
902+
903+
expect(JSON.parse(readSource('pageTreeData.rocketGenerated.json'))).to.deep.equal({
904+
h1: 'Home',
905+
headlinesWithId: [
906+
{
907+
id: 'home',
908+
level: 1,
909+
rawText: 'Welcome to Rocket',
910+
text: 'Home',
911+
},
912+
{
913+
id: 'first',
914+
level: 2,
915+
text: 'First',
916+
},
917+
{
918+
id: 'second',
919+
level: 2,
920+
rawText: 'Second is best',
921+
text: 'Second',
922+
},
923+
],
924+
level: 0,
925+
menuLinkText: 'Home',
926+
name: 'Home',
927+
outputRelativeFilePath: 'index.html',
928+
sourceRelativeFilePath: 'index.rocket.js',
929+
url: '/',
930+
});
931+
});
896932
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* START - Rocket auto generated - do not touch */
2+
export const sourceRelativeFilePath = 'index.rocket.js';
3+
import { layout, html } from './recursive.data.js';
4+
export { layout, html };
5+
/* END - Rocket auto generated - do not touch */
6+
7+
export default () => html`
8+
<h1 id="home" link-text="Home">Welcome to Rocket</h1>
9+
<h2 id="first">First</h2>
10+
<h2 link-text="Second" id="second">Second is best</h2>
11+
`;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"h1": "Home",
3+
"headlinesWithId": [
4+
{
5+
"text": "Home",
6+
"id": "home",
7+
"level": 1,
8+
"rawText": "Welcome to Rocket"
9+
},
10+
{
11+
"text": "First",
12+
"id": "first",
13+
"level": 2
14+
},
15+
{
16+
"text": "Second",
17+
"id": "second",
18+
"level": 2,
19+
"rawText": "Second is best"
20+
}
21+
],
22+
"name": "Home",
23+
"menuLinkText": "Home",
24+
"url": "/",
25+
"outputRelativeFilePath": "index.html",
26+
"sourceRelativeFilePath": "index.rocket.js",
27+
"level": 0
28+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { PageTree, SiteMenu } from '@rocket/engine';
2+
import { html } from 'lit';
3+
4+
const pageTree = new PageTree({
5+
inputDir: new URL('./', import.meta.url),
6+
outputDir: new URL('../__output', import.meta.url),
7+
});
8+
9+
await pageTree.restore();
10+
11+
export const layout = data => {
12+
return html`
13+
${pageTree.renderMenu(new SiteMenu(), data.sourceRelativeFilePath)}
14+
<main>${data.content()}</main>
15+
`;
16+
};
17+
18+
export { html };

site/pages/10--docs/20--basics/70--navigation.rocket.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,22 @@ In most cases you probably will not need to do anything as it will take the text
8585
So if you have a page like this:
8686
8787
```md
88-
# Hello World
88+
# Learning Rocket
8989
```
9090
91-
then it will be called "Hello World" in the menu.
91+
then it will be called "Learning Rocket" in the menu.
9292
9393
You can overwrite that by using the property `menuLinkText`;
9494
9595
````md
9696
```js server
97-
export const menuLinkText = 'Hello';
97+
export const menuLinkText = 'Docs';
9898
```
9999
100-
# Hello World
100+
# Learning Rocket
101101
````
102102
103-
Now the menu will be called "Hello".
103+
Now the menu will be called "Docs".
104104
105105
Within a menu the text of the links is defined by the following priority:
106106
@@ -111,6 +111,23 @@ Within a menu the text of the links is defined by the following priority:
111111
112112
You can influence that data that gets provided to the menu by setting exports.
113113
114+
### link-text="..."
115+
116+
If you want to rename the menu text you can use the attribute `link-text`.
117+
It works on your h1 for the page title as well as on your h2-h6 for a table of contents menu.
118+
119+
Examples:
120+
121+
```html
122+
<h1 link-text="Docs">Learning Rocket</h1>
123+
124+
<h2 link-text="Contact">Write us a message</h2>
125+
```
126+
127+
<inline-notification>
128+
You can use HTML within markdown too!
129+
</inline-notification>
130+
114131
## Headings with HTML
115132
116133
HTML in headings will be ignored for the menu

0 commit comments

Comments
 (0)