-
Notifications
You must be signed in to change notification settings - Fork 10
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
Adding dynamic, configurable, meta component, to page template #73
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
bad3d07
fix: adding meta web component
hutchgrant ecfb61e
fix: adding meta component to default page template and scaffold
hutchgrant 188b18b
fix: resolving lint issues
hutchgrant 00a056a
Merge branch 'master' of github.com:ProjectEvergreen/greenwood into t…
hutchgrant 883c295
fix: merge config meta with graph, updated meta component to prevent …
hutchgrant 3e23368
fix: merge config meta with graph, updated meta component to prevent …
hutchgrant ca68b40
fix: remove leftovers from merge
hutchgrant ba67bad
fix: refactor
hutchgrant 647cc83
fix: update meta summary comment
hutchgrant fe4a7b4
test: adding tests for title and meta
hutchgrant 2afc21a
test: adding more tests for og:url and og:title
hutchgrant b772c9a
fix: small refactor
hutchgrant 3361a74
fix: small refactor
hutchgrant 3ab9cba
Merge branch 'master' of github.com:ProjectEvergreen/greenwood into t…
hutchgrant b10607d
test: adding meta config tests
hutchgrant 3de7878
fix: cleanup test description and summary
hutchgrant 0599e68
fix: re-enable meta teardown
hutchgrant b475ba5
test: seperating meta and title tests, modifying smoke-tests, adding …
hutchgrant 7077836
test: cleanup
hutchgrant 2c08054
Merge branch 'master' into task/fix-issue-5-meta
thescientist13 416a1d5
test: updating custom styled page-template test
hutchgrant 81cbb33
test: add meta smoke-test
hutchgrant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,72 @@ | ||
import { html, LitElement } from 'lit-element'; | ||
|
||
/* | ||
* Take an attributes object with an array of meta objects, add them to an element and replace/add the element to DOM | ||
* { | ||
* title: 'my title', | ||
* meta: [ | ||
* { property: 'og:site', content: 'greenwood' }, | ||
* { name: 'twitter:site', content: '@PrjEvergreen ' } | ||
* ] | ||
* } | ||
*/ | ||
|
||
class meta extends LitElement { | ||
|
||
static get properties() { | ||
return { | ||
attributes: { | ||
type: Object | ||
} | ||
}; | ||
} | ||
|
||
firstUpdated() { | ||
let header = document.head; | ||
let meta; | ||
|
||
if (this.attributes) { | ||
this.attributes.meta.map(attr => { | ||
meta = document.createElement('meta'); | ||
|
||
const metaPropertyOrName = Object.keys(attr)[0]; | ||
const metaPropValue = Object.values(attr)[0]; | ||
let metaContentVal = Object.values(attr)[1]; | ||
|
||
// insert origin domain into url | ||
if (metaPropValue === 'og:url') { | ||
metaContentVal = window.location.origin + metaContentVal; | ||
} | ||
|
||
meta.setAttribute(metaPropertyOrName, metaPropValue); | ||
meta.setAttribute('content', metaContentVal); | ||
|
||
const oldmeta = header.querySelector(`[${metaPropertyOrName}="${metaPropValue}"]`); | ||
|
||
// rehydration | ||
if (oldmeta) { | ||
header.replaceChild(meta, oldmeta); | ||
} else { | ||
header.appendChild(meta); | ||
} | ||
}); | ||
let title = document.createElement('title'); | ||
|
||
title.innerText = this.attributes.title; | ||
const oldTitle = document.head.querySelector('title'); | ||
|
||
header.replaceChild(title, oldTitle); | ||
} | ||
|
||
} | ||
|
||
render() { | ||
return html` | ||
<div> | ||
|
||
</div> | ||
`; | ||
} | ||
} | ||
|
||
customElements.define('eve-meta', meta); |
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
44 changes: 44 additions & 0 deletions
44
test/cli/cases/build.config.error-title/build.config.error-title.spec.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,44 @@ | ||
/* | ||
* Use Case | ||
* Run Greenwood build command with a bad value for title in a custom config. | ||
* | ||
* User Result | ||
* Should throw an error. | ||
* | ||
* User Command | ||
* greenwood build | ||
* | ||
* User Config | ||
* { | ||
* title: {} | ||
* } | ||
* | ||
* User Workspace | ||
* Greenwood default | ||
*/ | ||
const expect = require('chai').expect; | ||
const TestBed = require('../../test-bed'); | ||
|
||
describe('Build Greenwood With: ', () => { | ||
let setup; | ||
|
||
before(async () => { | ||
setup = new TestBed(); | ||
setup.setupTestBed(__dirname); | ||
}); | ||
|
||
describe('Custom Configuration with a bad value for Title', () => { | ||
it('should throw an error that title must be a string', async () => { | ||
try { | ||
await setup.runGreenwoodCommand('build'); | ||
} catch (err) { | ||
expect(err).to.contain('greenwood.config.js title must be a string'); | ||
} | ||
}); | ||
}); | ||
|
||
after(function() { | ||
setup.teardownTestBed(); | ||
}); | ||
|
||
}); |
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 @@ | ||
module.exports = { | ||
title: {} | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be a good candidate as a POC for our "first" (second) package in our (pending) monorepo in terms of coming up with an initial approach for how consumers can extend Greenwood. (markup anyway)
Maybe some sort of configuration where users can provide these placeholder (or Greenwood can provide standard ones, like
META
) and then we can have plugins for each of these "hooks".I think it will be good to consider this to help avoid a giant configuration file. Even something like meta could become complex and warrant its own standalone package / API.
My guess is users will include / configure plugins like this and pass it into our configuration.
Just thinking out load, but seems like we could probably get a basic RFC drummed up from this idea for a post Sprint 2 enhancement (basically a "use the platform" version of react-helmet?. 🤔 💡
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this as well, I was tempted to add this to my evergreen web component library That way, there would be no issue with importing it.