-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Gh 2 add support for storyblok
Showing
6 changed files
with
109 additions
and
15 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,53 @@ | ||
import { | ||
IECheckFunction, | ||
IETransformFunction, | ||
IEDefaultPlatform, | ||
} from "../types"; | ||
|
||
import { node_create, REPLACEMENT_TOKEN } from "../helpers/nodes_helpers.js"; | ||
|
||
const default_replace_url: string = "https://a.storyblok.com/"; | ||
|
||
const checker: IECheckFunction = (node_object) => { | ||
let internal = node_object?.node?.internal; | ||
const isStoryblok = internal && internal.type === "StoryblokEntry"; | ||
|
||
if (isStoryblok) { | ||
let content = JSON.parse(node_object.node.content); | ||
return content.assets !== undefined; | ||
} | ||
return isStoryblok; | ||
}; | ||
|
||
const transformer: IETransformFunction = ( | ||
node_object, | ||
options, | ||
global_options | ||
) => { | ||
let dist_url = | ||
options?.ie_delivery_address || global_options?.ie_delivery_address; | ||
let directives = options?.directives || global_options?.directives; | ||
let replace_url = options?.replace_url || default_replace_url; | ||
let content = JSON.parse(node_object.node.content); | ||
if (content.assets) { | ||
let filename = content.assets.filename; | ||
|
||
let tokenized_url = filename.replace(replace_url, REPLACEMENT_TOKEN); | ||
return node_create( | ||
node_object, | ||
filename, | ||
tokenized_url, | ||
dist_url, | ||
directives, | ||
node_object?.node?.internal.mediaType | ||
); | ||
} | ||
return null; | ||
}; | ||
|
||
const platform: IEDefaultPlatform = { | ||
checker: checker, | ||
transformer: transformer, | ||
}; | ||
|
||
export default platform; |
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