-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
470 additions
and
40 deletions.
There are no files selected for viewing
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
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
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
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,116 @@ | ||
import chai from 'chai'; | ||
import { setupTestCli } from './test-helpers.js'; | ||
|
||
const { expect } = chai; | ||
|
||
describe('Open Graph', () => { | ||
it('generates the image and adds the meta tags', async () => { | ||
const { build, readOutput, outputExists } = await setupTestCli( | ||
'fixtures/04-open-graph/01-generate-image-and-inject-meta', | ||
undefined, | ||
{ | ||
buildOptimize: true, | ||
}, | ||
); | ||
await build(); | ||
|
||
expect(readOutput('index.html', { replaceImageHashes: true })).to.equal( | ||
[ | ||
'<!DOCTYPE html>', | ||
'<html lang="en">', | ||
' <head>', | ||
' <meta charset="utf-8" />', | ||
' <meta property="og:image:width" content="2400" />', | ||
' <meta property="og:image:height" content="1256" />', | ||
' <meta property="og:image" content="http://my-site.com/__HASH__.png" />', | ||
' </head>', | ||
' <body>', | ||
' <h1>Hello World!</h1>', | ||
' </body>', | ||
'</html>', | ||
].join('\n'), | ||
); | ||
|
||
expect(outputExists('./index.opengraph.html')).to.be.false; | ||
}); | ||
|
||
it('handles multiple pages', async () => { | ||
const { build, readOutput } = await setupTestCli( | ||
'fixtures/04-open-graph/02-multiple-pages', | ||
undefined, | ||
{ | ||
buildOptimize: true, | ||
}, | ||
); | ||
await build(); | ||
|
||
expect(readOutput('index.html', { replaceImageHashes: true })).to.equal( | ||
[ | ||
'<!DOCTYPE html>', | ||
'<html lang="en">', | ||
' <head>', | ||
' <meta charset="utf-8" />', | ||
' <meta property="og:image:width" content="2400" />', | ||
' <meta property="og:image:height" content="1256" />', | ||
' <meta property="og:image" content="http://my-site.com/__HASH__.png" />', | ||
' </head>', | ||
' <body>', | ||
' <h1>Hello World!</h1>', | ||
' </body>', | ||
'</html>', | ||
].join('\n'), | ||
); | ||
|
||
expect(readOutput('components/index.html', { replaceImageHashes: true })).to.equal( | ||
[ | ||
'<!DOCTYPE html>', | ||
'<html lang="en">', | ||
' <head>', | ||
' <meta charset="utf-8" />', | ||
' <meta property="og:image:width" content="2400" />', | ||
' <meta property="og:image:height" content="1256" />', | ||
' <meta property="og:image" content="http://my-site.com/__HASH__.png" />', | ||
' </head>', | ||
' <body>', | ||
' <h1>Components</h1>', | ||
' </body>', | ||
'</html>', | ||
].join('\n'), | ||
); | ||
|
||
expect(readOutput('components/accordion/index.html', { replaceImageHashes: true })).to.equal( | ||
[ | ||
'<!DOCTYPE html>', | ||
'<html lang="en">', | ||
' <head>', | ||
' <meta charset="utf-8" />', | ||
' <meta property="og:image:width" content="2400" />', | ||
' <meta property="og:image:height" content="1256" />', | ||
' <meta property="og:image" content="http://my-site.com/__HASH__.png" />', | ||
' </head>', | ||
' <body>', | ||
' <h1>Accordion</h1>', | ||
' </body>', | ||
'</html>', | ||
].join('\n'), | ||
); | ||
|
||
// This image is "wrong" as it does not output the page title as the page is not added to the page tree | ||
expect(readOutput('components/special.html', { replaceImageHashes: true })).to.equal( | ||
[ | ||
'<!DOCTYPE html>', | ||
'<html lang="en">', | ||
' <head>', | ||
' <meta charset="utf-8" />', | ||
' <meta property="og:image:width" content="2400" />', | ||
' <meta property="og:image:height" content="1256" />', | ||
' <meta property="og:image" content="http://my-site.com/__HASH__.png" />', | ||
' </head>', | ||
' <body>', | ||
' <h1>Special</h1>', | ||
' </body>', | ||
'</html>', | ||
].join('\n'), | ||
); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
...est-node/fixtures/04-open-graph/01-generate-image-and-inject-meta/config/rocket.config.js
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 @@ | ||
export default /** @type {import('../../../../../types/main').RocketCliOptions} */ ({ | ||
absoluteBaseUrl: 'http://my-site.com', | ||
}); |
7 changes: 7 additions & 0 deletions
7
...-node/fixtures/04-open-graph/01-generate-image-and-inject-meta/site/pages/index.rocket.js
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,7 @@ | ||
/* START - Rocket auto generated - do not touch */ | ||
export const sourceRelativeFilePath = 'index.rocket.js'; | ||
import { layout, openGraphLayout, html } from './local.data.js'; | ||
export { layout, openGraphLayout, html }; | ||
/* END - Rocket auto generated - do not touch */ | ||
|
||
export default () => html`<h1>Hello World!</h1>`; |
32 changes: 32 additions & 0 deletions
32
...st-node/fixtures/04-open-graph/01-generate-image-and-inject-meta/site/pages/local.data.js
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,32 @@ | ||
import { PageTree } from '@rocket/engine'; | ||
import { html } from 'lit'; | ||
|
||
export const layout = data => html` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
${data.content()} | ||
</body> | ||
</html> | ||
`; | ||
|
||
const pageTree = new PageTree(); | ||
await pageTree.restore(new URL('./pageTreeData.rocketGenerated.json', import.meta.url)); | ||
|
||
export const openGraphLayout = data => html` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<h1>${pageTree.getPage(data.sourceRelativeFilePath)?.model?.name}</h1> | ||
<footer>Generated by <a href="https://next.rocket.modern-web.dev/">Rocket</a></footer> | ||
</body> | ||
</html> | ||
`; | ||
|
||
export { html }; |
9 changes: 9 additions & 0 deletions
9
...open-graph/01-generate-image-and-inject-meta/site/pages/pageTreeData.rocketGenerated.json
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,9 @@ | ||
{ | ||
"h1": "Hello World!", | ||
"name": "Hello World!", | ||
"menuLinkText": "Hello World!", | ||
"url": "/", | ||
"outputRelativeFilePath": "index.html", | ||
"sourceRelativeFilePath": "index.rocket.js", | ||
"level": 0 | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/cli/test-node/fixtures/04-open-graph/02-multiple-pages/config/rocket.config.js
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 @@ | ||
export default /** @type {import('../../../../../types/main').RocketCliOptions} */ ({ | ||
absoluteBaseUrl: 'http://my-site.com', | ||
}); |
7 changes: 7 additions & 0 deletions
7
...t-node/fixtures/04-open-graph/02-multiple-pages/site/pages/components/accordion.rocket.js
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,7 @@ | ||
/* START - Rocket auto generated - do not touch */ | ||
export const sourceRelativeFilePath = 'components/accordion.rocket.js'; | ||
import { layout, openGraphLayout, html } from '../recursive.data.js'; | ||
export { layout, openGraphLayout, html }; | ||
/* END - Rocket auto generated - do not touch */ | ||
|
||
export default () => html`<h1>Accordion</h1>`; |
7 changes: 7 additions & 0 deletions
7
.../test-node/fixtures/04-open-graph/02-multiple-pages/site/pages/components/index.rocket.js
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,7 @@ | ||
/* START - Rocket auto generated - do not touch */ | ||
export const sourceRelativeFilePath = 'components/index.rocket.js'; | ||
import { layout, openGraphLayout, html } from '../recursive.data.js'; | ||
export { layout, openGraphLayout, html }; | ||
/* END - Rocket auto generated - do not touch */ | ||
|
||
export default () => html`<h1>Components</h1>`; |
7 changes: 7 additions & 0 deletions
7
...ode/fixtures/04-open-graph/02-multiple-pages/site/pages/components/special.html.rocket.js
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,7 @@ | ||
/* START - Rocket auto generated - do not touch */ | ||
export const sourceRelativeFilePath = 'components/special.html.rocket.js'; | ||
import { layout, openGraphLayout, html } from '../recursive.data.js'; | ||
export { layout, openGraphLayout, html }; | ||
/* END - Rocket auto generated - do not touch */ | ||
|
||
export default () => html`<h1>Special</h1>`; |
7 changes: 7 additions & 0 deletions
7
packages/cli/test-node/fixtures/04-open-graph/02-multiple-pages/site/pages/index.rocket.js
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,7 @@ | ||
/* START - Rocket auto generated - do not touch */ | ||
export const sourceRelativeFilePath = 'index.rocket.js'; | ||
import { layout, openGraphLayout, html } from './recursive.data.js'; | ||
export { layout, openGraphLayout, html }; | ||
/* END - Rocket auto generated - do not touch */ | ||
|
||
export default () => html`<h1>Hello World!</h1>`; |
Oops, something went wrong.