Skip to content

Commit

Permalink
Merge branch 'stage' of github.com:Adventech/sabbath-school-resources…
Browse files Browse the repository at this point in the history
… into stage
  • Loading branch information
VitalikL committed Nov 19, 2023
2 parents 1da0b83 + 12af6fa commit 6db94c2
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 34 deletions.
2 changes: 1 addition & 1 deletion ops/helpers/blocks/poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const poll = {
name: "poll",
level: "block",
tokenizer(src, tokens) {
const rule = /^ {0,3}(\?{3,}(?=[^?\n]*\n))=([^\n]+)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[?]* *(?=\n|$)|$)/
const rule = /^^(\?{3,}(?=[^\n]*\n))=([^\n]+)\n(?:|([\s\S]*?)\n)(?:\1[?]* *(?=\n|$)|$)/
const match = rule.exec(src);
if (match) {
return {
Expand Down
69 changes: 60 additions & 9 deletions ops/helpers/blocks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,75 @@ const styleSchema = {
"type": "object",
"additionalProperties": false,
"properties": {
// "rounded": {"type": "boolean"},
// "expandable": {"type": "boolean"},
// "position": {"type": "string", "enum": ["start", "center", "end"]},
// "size": {"type": "string", "enum": ["small", "medium", "large"]},
// "fullBleed": {"type": "boolean"},
"aspectRatio": { "type": "number" },
"typeface": { "type": "string" },
"block": {
"type": "object",
"additionalProperties": false,
"properties": {
"backgroundColor": { "type": "string" },
"padding": {
"type": "object",
"additionalProperties": false,
"properties": {
"top": { "type": "string", "enum": [ "none", "xs", "sm", "base", "lg", "xl", ] },
"bottom": { "type": "string", "enum": [ "none", "xs", "sm", "base", "lg", "xl", ] },
"start": { "type": "string", "enum": [ "none", "xs", "sm", "base", "lg", "xl", ] },
"end": { "type": "string", "enum": [ "none", "xs", "sm", "base", "lg", "xl", ] },
},"anyOf": [
{ "required": ["top"], },
{ "required": ["bottom"], },
{ "required": ["start"], },
{ "required": ["send"], },
]
},
"margin": {
"type": "object",
"additionalProperties": false,
"properties": {
"top": { "type": "string", "enum": [ "none", "xs", "sm", "base", "lg", "xl", ] },
"bottom": { "type": "string", "enum": [ "none", "xs", "sm", "base", "lg", "xl", ] },
"start": { "type": "string", "enum": [ "none", "xs", "sm", "base", "lg", "xl", ] },
"end": { "type": "string", "enum": [ "none", "xs", "sm", "base", "lg", "xl", ] },
},
"anyOf": [
{ "required": ["top"], },
{ "required": ["bottom"], },
{ "required": ["start"], },
{ "required": ["send"], },
]
},
}
},

// special block-level styles
"image": {
"type": "object",
"additionalProperties": false,
"properties": {
"aspectRatio": { "type": "number" },
}
},
"text": {
"type": "object",
"additionalProperties": false,
"properties": {
"typeface": { "type": "string" },
"color": { "type": "string" },
"size": { "type": "string", "enum": [ "xs", "sm", "base", "lg", "xl", ] },
"align": { "type": "string", "enum": [ "start", "end", "center", ] },
"offset": { "type": "string", "enum": [ "sup", "sub", ] },
},
},

}
}

export const style = function (block) {
let blockStyle = {}
let sspmOptionsRegex = /({\s*"style"\s*:.*})/g
let sspmOptionsRegex = /^({\s*"style"\s*:.*})/g
let sspmOptionsMatch = block.raw.match(sspmOptionsRegex)

if (sspmOptionsMatch && sspmOptionsMatch[0]) {
try {
console.log(`matching`, sspmOptionsMatch[0])
let sspmOptions = JSON.parse(sspmOptionsMatch[0])
let validateResult = jsonSchemaValidate(sspmOptions.style, styleSchema)
if (validateResult.errors.length < 1) {
Expand Down
27 changes: 14 additions & 13 deletions ops/helpers/blocks/superscript.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
let superscriptReplacement = function (str) {
const unicodeMap = ["⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹"]
let ret = str
for (let i = 0; i <= 9; i++) {
ret = ret.replace(new RegExp(`${i}`, "gm"), unicodeMap[i])
}
return ret
}

export const superscript = function (block) {
let sspmSuperscript = /(~|<sup>)(\d*)(~|<\/sup>)/img
let sspmSuperscript = /(~|<sup>)(.*)(~|<\/sup>)/img
let sspmSuperscriptMatch = block.raw.match(sspmSuperscript)


if (sspmSuperscriptMatch && sspmSuperscriptMatch.length > 0) {
for (let match of sspmSuperscriptMatch) {
let unicodeNumber = superscriptReplacement(match.replace(sspmSuperscript, "$2"))
block.text = block.text.replace(match, unicodeNumber).trim()
let superscript = match.replace(sspmSuperscript, "$2")
block.text = block.text.replace(match, `^[${superscript}]({"style":{"text":{"offset": "sup"}}})`).trim()
}
}

let sspmSubscript = /(~|<sub>)(.*)(~|<\/sub>)/img
let sspmSubscriptMatch = block.raw.match(sspmSubscript)

if (sspmSubscriptMatch && sspmSubscriptMatch.length > 0) {
for (let match of sspmSubscriptMatch) {
let subscript = match.replace(sspmSubscript, "$2")
block.text = block.text.replace(match, `^[${subscript}]({"style":{"text":{"offset": "sub"}}})`).trim()
}
}

return block
}
1 change: 1 addition & 0 deletions ops/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const API_DIST = `${DIST_DIR}/${API_PREFIX}`
export const API_URL = function () { return `https://sabbath-school${DEPLOY_ENV === "prod" ? "" : "-stage" }.adventech.io` }
export const MEDIA_URL = `https://sabbath-school-resources-media.adventech.io`
export const FIREBASE_DATABASE_NAME = (DEPLOY_ENV === "prod") ? "https://blistering-inferno-8720.firebaseio.com" : "https://sabbath-school-stage.firebaseio.com"
export const FIREBASE_DATABASE_LANGUAGES = "languages"
export const FIREBASE_DATABASE_RESOURCES = "resources"
export const FIREBASE_DATABASE_BLOCKS = "blocks"
export const FIREBASE_DATABASE_DOCUMENTS = "documents"
Expand Down
6 changes: 3 additions & 3 deletions ops/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ let determineFontWeight = async function (fontStr) {
500: /Medium/i,
600: /(Semi|Demi)([- _])?Bold/i,
700: /Bold/i,
800: /(Extra|Ultra)([- _])?Bold/i,
900: /Black|Heavy/i,
800: /((Extra|Ultra)([- _])?Bold)|Heavy/i,
900: /Black/i,
}
for (let weight of Object.keys(weights)) {
if (weights[weight].test(fontStr)) {
return weight
}
}
return null
return 400
}

let getImageRatio = async function (src) {
Expand Down
7 changes: 5 additions & 2 deletions ops/sync/set-aspect-ratios.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@ let setImageAspectRatios = async function (resourceType) {
let style = imageBlock.style || {}
let aspectRatio

if (!style.aspectRatio) {
if (!style.image || !style.image.aspectRatio) {
if (isURL(imageBlock.src)) {
aspectRatio = await getImageRatio(await getBufferFromUrl(imageBlock.src))
} else {
aspectRatio = await getImageRatio(`${SOURCE_DIR}/${documentPathInfo.language}/${documentPathInfo.type}/${documentPathInfo.title}/${RESOURCE_ASSETS_DIRNAME}/${imageBlock.src}`)
}
style.aspectRatio = aspectRatio
if (!style["image"]) {
style["image"] = {}
}
style["image"].aspectRatio = aspectRatio

replace.push([
new RegExp(`(^\{"style".*\n)?!\\[${imageBlock.caption}\\]\\(${imageBlock.src}\\)`, "gm"),
Expand Down
4 changes: 2 additions & 2 deletions ops/sync/transfer-resource-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ let transferResourcesFonts = async function () {
if (postScriptName) {
postScriptName = postScriptName.text.replaceAll("\x00", "")
let weight = await determineFontWeight(postScriptName)

if (weight) {
// weird bug of the ttfInfo library, replacing \x00 with nothing
resourceInfo.fonts.push({
Expand All @@ -206,7 +205,8 @@ let transferResourcesFonts = async function () {
}
}

if (mode === "remote") fs.outputFileSync(resourceInfoFile, yaml.dump(resourceInfo))
// if (mode === "remote")
fs.outputFileSync(resourceInfoFile, yaml.dump(resourceInfo))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/en/devo/test-2/content/blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ _test_

{#[en/pm/discipleship-handbook/content/01-discipleship/01-to-be-like-jesus.md]}

{"style":{"aspectRatio":1.514}}
{"style":{"image":{"aspectRatio":1.514}}}
![Walrus image](https://sabbath-school-resources-media.adventech.io/en/devo/test/assets/fisherman.jpg)

{"style":{"aspectRatio":1.514}}
{"style":{"image":{"aspectRatio":1.514}}}
![penguin image](https://sabbath-school-resources-media.adventech.io/en/devo/test/assets/fisherman.jpg)

!a[https://sabbath-school-resources-media.adventech.io/en/devo/test/assets/45755e5bc007ecf3571c22de2cf3d8422630c02ac5c582b27f78c64035192b1d.mp4] with caption
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions src/en/devo/test/content/blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ Split this one

`Question please?`

{"style":{"image":{"aspectRatio":1.778}}}
![test](60aec3c8b8186d6fc8c0e04c.jpg)
{"style":{"aspectRatio":1.778}}
![test](https://sabbath-school-resources-media.adventech.io/en/devo/test/assets/60aec3c8b8186d6fc8c0e04c.jpg)

Hello <sup>1</sup> In the beginning God created the heavens and the earth.

Expand Down

0 comments on commit 6db94c2

Please sign in to comment.