This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #805 from B77Mills/gtmNativeXStory
Add compoents/builder for nativeXStory GTM context
- Loading branch information
Showing
4 changed files
with
54 additions
and
0 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
9 changes: 9 additions & 0 deletions
9
packages/marko-web-gtm/components/context/native-x-story.marko
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 @@ | ||
import { isFunction, warn } from "@parameter1/base-cms-utils"; | ||
import { nativeXStoryBuilder } from "../../context"; | ||
|
||
$ const { req } = out.global; | ||
$ const builder = isFunction(input.builder) ? input.builder : nativeXStoryBuilder; | ||
$ const type = input.type || "content"; | ||
|
||
$ const context = builder({ type, obj: input.obj, req }); | ||
<${input.renderBody} context=context /> |
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,37 @@ | ||
const { getAsObject, getAsArray, get } = require('@parameter1/base-cms-object-path'); | ||
const { asObject } = require('@parameter1/base-cms-utils'); | ||
const buildQueryString = require('../utils/build-query-string'); | ||
|
||
module.exports = ({ type, obj, req }) => { | ||
const content = asObject(obj); | ||
const company = getAsObject(content, 'company'); | ||
const section = getAsObject(content, 'primarySection'); | ||
const hierarchy = getAsArray(section, 'hierarchy').map((s) => ({ | ||
id: s.id, | ||
name: s.name, | ||
alias: s.alias, | ||
})); | ||
return { | ||
page_type: type, | ||
canonical_path: get(content, 'siteContext.path'), | ||
query_string: buildQueryString({ req }), | ||
content: { | ||
id: content.id, | ||
type: content.type, | ||
name: content.name, | ||
published: content.published ? new Date(content.published).toISOString() : undefined, | ||
labels: getAsArray(content, 'labels'), | ||
}, | ||
company: { | ||
id: company.id, | ||
name: company.name, | ||
}, | ||
section: { | ||
id: section.id, | ||
name: section.name, | ||
alias: section.alias, | ||
fullName: section.fullName, | ||
}, | ||
section_hierarchy: hierarchy, | ||
}; | ||
}; |