-
Notifications
You must be signed in to change notification settings - Fork 19
feat(html pipe): Default pipeline should include <section/>s #379
Conversation
Trying to gather some early feedback to validate the approach before spending too much time on re-writing the tests |
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.
Looks good so far.
src/html/get-metadata.js
Outdated
@@ -19,7 +19,7 @@ const { | |||
|
|||
function yaml(section) { | |||
const yamls = selectAll('yaml', section); | |||
section.meta = obj(flat(map(yamls, ({ payload }) => payload))); | |||
section.meta = Object.assign({}, obj(flat(map(yamls, ({ payload }) => payload)))); |
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.
Why the additional Object.assign
?
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.
👍 Some left-overs from testing various approaches. I'll definitely remove in the final PR.
src/html/split-sections.js
Outdated
@@ -11,8 +11,15 @@ | |||
*/ | |||
|
|||
const between = require('unist-util-find-all-between'); | |||
const { selectAll } = require('unist-util-select'); | |||
const { flat, obj, map } = require('@adobe/helix-shared').sequence; |
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'd import @adobe/ferrum
directly
src/html/get-metadata.js
Outdated
@@ -144,7 +144,8 @@ function fallback(section) { | |||
} | |||
|
|||
function getmetadata({ content }, { logger }) { | |||
const { sections } = content; | |||
const { mdast: { children } } = content; | |||
const sections = children.filter(node => node.type === 'root'); |
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.
Can this work? Below, you are changing the type to section
.
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.
👍 Again, some left-overs from playing around… though it should have failed somehow. Will double-check
return { | ||
type: 'root', | ||
const section = { | ||
type: 'section', |
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.
New node type is a good idea.
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.
Is it ok to just inline the node type or do we have a central place to expose them as enum constants that I could use?
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.
maybe a schema would be in order?
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.
@rofe I added a schema, and updated existing ones accordingly with the changes.
Was just wondering if we have a sort of global "constants" file where I would be pulling the string from, or if it is ok to just inline for now
src/schemas/mdast.schema.json
Outdated
@@ -76,15 +77,21 @@ | |||
"imageReference": "A pointer to an image", | |||
"footnote": "A footnote", | |||
"footnoteReference": "A reference to a footnote", | |||
"embed": "Content embedded from another page, identified by the `url` attribute." | |||
"embed": "Content embedded from another page, identified by the `url` attribute.", | |||
"section": "The extracted sections of the document" |
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.
"section": "The extracted sections of the document" | |
"section": "A section within the document. Sections serve as a high-level structure of a single markdown document and can have their own section-specific front matter metadata." |
src/utils/section-handler.js
Outdated
* @returns {string} The tag name for the section. Defaults to {@code div}. | ||
*/ | ||
function getTageName(section) { | ||
return (section.meta && section.meta.tagName) || 'div'; |
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.
Can we not use camelCase for YAML properties? tagname
should be sufficient.
src/utils/section-handler.js
Outdated
* @returns {string} The class name for the section. Defaults to {@code hlx-section}. | ||
*/ | ||
function getClass(section) { | ||
return (section.meta && section.meta.className) || 'hlx-section'; |
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.
Same here, the YAML property should be class
, even if it is slightly inconvenient to read it from JavaScript.
Also, what happens to the detected section types?
src/utils/section-handler.js
Outdated
// we have a section that is not the document root, so wrap it in the desired tag | ||
if (parent && parent.type === 'root' && parent.children.length > 1) { | ||
const tagName = getTageName(n); | ||
const props = { class: getClass(n), 'data-hlx-types': getTypes(n) }; |
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'd rather merge the types
into class
and then have data-<prop
for each additional prop
that's in the section metadata.
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.
@trieloff So, something like this?
<div class="hlx-Section hlx-Section--hasImage hlx-Section--nbImage1 hlx-Section--hasOnlyImage" data-hlx-<meta1>="<value1>" data-hlx-<meta2>="<value2>" …></div>
And we let the dev:
- overwrite the section class
- toggle whether type classes are added (and use the custom section class as prefix if set)
- toggle whether additional meta props are exposed as data attributes
I went with the SUIT CSS naming convention, but we could also do:
<div class="hlx-section has-image nb-image-1 has-only-image" data-hlx-<meta1>="<value1>" data-hlx-<meta2>="<value2>" …></div>
We just run a higher risk of collisions with domain specific CSS class names
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.
Yes, except that classnames should be lowercase and should be kept as they are (your lower example).
We can fix the collisions later, i.e. through a step that performs class renaming.
My reason for this is that the HTML is simpler, and writing CSS selectors for attributes is harder than for classes, so I'd err on the side of simplicity over consistency.
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.
@trieloff If we assume a step that does the renaming, then does it make sense to let the author specify the section class name in the first place in the yaml? I could just hardcode hlx-section
then.
Less logic => fewer risk of bugs
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 think allowing to specify the class name is a useful quick fix for some scenarios.
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 don't think we need to prefix the section
with hlx-section
as i think that the entire default DOM is a helix DOM and in case of a conflict the or some other desire to change the DOM it is very easily done in a the pre.js
via jquery or regular DOM manipulation.
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.
Looks good so far. I guess eslint
is still angry at you.
@trieloff Mostly the tests are failing since I did not touch them yet. Wanted to first validate the approach |
Keep going, you are on the right track. |
Codecov Report
@@ Coverage Diff @@
## master #379 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 48 50 +2
Lines 1100 1150 +50
=====================================
+ Hits 1100 1150 +50
Continue to review full report at Codecov.
|
@@ -33,13 +33,6 @@ | |||
"mdast": { | |||
"$ref": "https://ns.adobe.com/helix/pipeline/mdast" | |||
}, | |||
"sections": { |
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.
BREAKING CHANGE: Sections is removed and added to the mdast
directly
| [label](#label) | `string` | Optional | No | MDAST (this schema) | | ||
| [lang](#lang) | `string` | Optional | Yes | MDAST (this schema) | | ||
| [meta](#meta) | `string` | Optional | Yes | MDAST (this schema) | | ||
| [meta](#meta) | `object` | Optional | Yes | MDAST (this schema) | |
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.
BREAKING CHANGE: the meta
now contains the yaml
meta information
@@ -33,13 +33,6 @@ | |||
"mdast": { | |||
"$ref": "https://ns.adobe.com/helix/pipeline/mdast" | |||
}, | |||
"sections": { |
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.
BREAKING CHANGE: as above in the doc
src/schemas/mdast.schema.json
Outdated
@@ -148,9 +153,29 @@ | |||
"format": "uri-reference", | |||
"description": "For resources, an url field must be present. It represents a URL to the referenced resource." | |||
}, | |||
"meta": { | |||
"type": ["null", "object"], |
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.
BREAKING CHANGE: as above in the doc
src/utils/section-handler.js
Outdated
|
||
const DEFAULT_SECTION_TAG = 'div'; | ||
const DEFAULT_SECTION_CLASS = 'hlx-section'; | ||
const SYSTEM_META_PROPERTIES = ['class', 'meta', 'tagname', 'types']; |
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.
YAML properties:
class {string}
: will allow overwriting the default section class (i.e.hlx-section
)meta {boolean}
: when set totrue
will output any additional YAML properties asdata-hlx-*
attributestagname {string}
: will allow overwriting the default section tag (i.e.div
)types {boolean}
: when set totrue
will output the section types as additional classes on the section (i.e.has-image
, etc.)
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.
Since meta
and types
are actual feature flags, should we follow a specific naming convention?
enable_meta
/enable_types
, output_meta
/output_types
, etc.
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 would only do that once we expose it as a config parameter.
@@ -1,42 +1,40 @@ | |||
[ |
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.
Just unwrapping the array since we unwrap sole sections directly on the mdast
} | ||
{ | ||
"type": "root", | ||
"children": [ |
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.
Just wrapping the array inside the mdast root's children
@@ -1,50 +1,48 @@ | |||
[ |
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.
Just unwrapping the array since we unwrap sole sections directly on the mdast
(same for rest of the sections fixtures below)
test/testConditionalSections.js
Outdated
@@ -441,7 +453,7 @@ Or that one at the same time, because they are both part of an A/B test. | |||
// format, section metadata, the mdast format or the input above, you probably | |||
// want to change one of these values until you find one that *happens* to work | |||
// again... | |||
assert.notDeepEqual(await runpipe('foo'), await runpipe('bang')); | |||
assert.notDeepEqual(await runpipe('foo'), await runpipe('bar')); |
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.
As per existing comment above, the test started failing after my changes, so tried out some other value
@@ -29,7 +29,7 @@ function callback(body) { | |||
parseFront(dat); | |||
split(dat, { logger }); | |||
getmetadata(dat, { logger }); | |||
return dat.content.sections; | |||
return dat.content.mdast; |
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.
Expose the mdast
node directly since most tests have a single section that will be unwrapped to it
assert.deepEqual(dat.content.meta, {}); | ||
}); | ||
|
||
it('getmetadata does not fail with missing sections', () => { |
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.
Removing this test since the empty mdast and missing sections are now the same.
Include proper sections in the HTML pipeline instead of plain <hr/> sectioning BREAKING CHANGE: Remove `context.content.sections` and move the sections directly under `context.content.mdast`; move the section types to the mdast `<node>.data.types`; move the section yaml meta info to `<node>.data.meta` fix #279
Include proper sections in the HTML pipeline instead of plain <hr/> sectioning fix #279
refactor existing tests and adjust code to properly support the new sections in the mdast fix #279
@@ -158,9 +157,9 @@ function getmetadata({ content }, { logger }) { | |||
|
|||
const img = sections.filter(section => section.image)[0]; | |||
|
|||
content.meta = empty(sections) ? {} : sections[0].meta; |
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.
sections will never be empty as we fall back to the mdast
node
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.
@ramboz merge when ready.
@ramboz for an example of |
nice find @trieloff , of course that one didn't work yet. i am really looking forward to having this implemented, looks great to me. |
BREAKING CHANGE: section types are moved to the sectio's meta object fix #279
After a quite lengthy discussion with @davidnuescheler, the conclusion is:
|
@trieloff As this requires changes in the IT tests in the cli, I'm not sure how to link the 2 branches together so the tests are passing. Any suggestion? |
@ramboz proceed carefully. Merge this branch, knowing that the smoke tests fail (and make sure they only fail in places you expect) then merge the fix in CLI. |
@trieloff Sounds good. Would have been great if the smoke test was smart enough to run from the same named branch instead of master in that case. Anyway, haven't merged directly here before. Anything special in the procedure, or can I just go ahead and squash-merge, then update cli accordingly? |
yes. |
# [4.0.0](v3.7.4...v4.0.0) (2019-07-05) ### Features * **html pipe:** Default pipeline should include <section/>s ([#379](#379)) ([27ad875](27ad875)), closes [adobe/helix-cli#1037](adobe/helix-cli#1037) [#279](#279) ### BREAKING CHANGES * **html pipe:** - Remove `context.content.sections` and move the sections directly under `context.content.mdast` - Adjust json schemas accordingly - Move the section yaml meta info to `<node>.meta` - Move the section types to the mdast `<node>.meta.types`
🎉 This PR is included in version 4.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Include proper sections in the HTML pipeline instead of plain
<hr>
sectioningBREAKING CHANGE:
context.content.sections
and move the sections directly undercontext.content.mdast
<node>.meta
<node>.meta.types
Is dependent on adobe/helix-cli#1037
fix #279