Working with Contentful Rich text with Jekll - jekyll

I'm trying to render a rich text field coming from Contentful into Jekyll.... but I can't get it to work. Has anyone had success with this? I already installed https://github.com/contentful/rich-text-renderer.rb as a gem & plugin, but there aren't any directions to make it work with Jekyll.
I am able to get the first paragraph with {{ page.body.content[0].content[0].value }} but clearly that's not the way. and {{ page.body.content | rich_text }} throws an error.
Anyone know how to get this to work?
here's the YML file if it helps
- sys:
id: 58za8Qb9b9ahqvxcTBTESb
created_at: !ruby/object:DateTime 2022-05-30 06:05:14.325000000 Z
updated_at: !ruby/object:DateTime 2022-05-30 17:45:38.289000000 Z
content_type_id: blogPost
revision: 8
title: This is for you Christine
link: this-is-for-you-christine
short_description: A working blog using Contentful and Jekyll
body:
nodeType: document
data: {}
content:
- nodeType: paragraph
data: {}
content:
- nodeType: text
value: 'Here it is... a wonderful thing. A headless static site-generated
blog. My JAMstack, you ask: '
marks: []
data: {}
- nodeType: unordered-list
data: {}
content:
- nodeType: list-item
data: {}
content:
- nodeType: paragraph
data: {}
content:
- nodeType: text
value: Contentful - CMS
marks: []
data: {}
- nodeType: list-item
data: {}
content:
- nodeType: paragraph
data: {}
content:
- nodeType: text
value: 'Github - repository, '
marks: []
data: {}
- nodeType: list-item
data: {}
content:
- nodeType: paragraph
data: {}
content:
- nodeType: text
value: 'Jekyll - SSG, '
marks: []
data: {}
- nodeType: list-item
data: {}
content:
- nodeType: paragraph
data: {}
content:
- nodeType: text
value: Netlify - hosting
marks: []
data: {}
- nodeType: list-item
data: {}
content:
- nodeType: paragraph
data: {}
content:
- nodeType: text
value: 'IDE - Gitpod '
marks: []
data: {}
- nodeType: paragraph
data: {}
content:
- nodeType: text
value: The cost of running. ABSOLUTELY FREE! Time to set up... once I knew
what to do, we won't discuss research time... but we can say I deserve another
3-day weekend. Aside... learned that I can understand developers speaking
in Portuguese... cause, yes, that's what it took! Anyway... time to set
up... under an hour. You're welcome! Of course, you are asking why this
is one large block paragraph? I still have to figure out displaying rich
text.
marks: []
data: {}

So it turns out that Contentful has a longText/Markdown option. So no need for rich text.

Related

Losing equations numbering when I render quarto document to word

I am losing equations numbering when I render quarto documents to word. This is what I have in my YAML metadata:
---
title: XXX
#author: "wananchi"
date: "`r Sys.Date()`"
format:
docx:
fontfamily: libertinus
fontsize: 11pt
spacing: double
toc: false
number-sections: true
editor: visual
bibliography: citations.bib
csl: apa.csl
---
And this is an example of one of my equations:
$$
ES_{w,t} = \varepsilon_wEP_{w,t}\tag{1}
$$
What could be the issue? I don't experience the problem when I render to pdf.
I tried using the code I specified above and seems like it's not working.
The equation numbering with \tag works for pdf output format, because \tag is a latex command, and with the help of MathJax, \tag also works for html output format, But it does not works for word document.
Therefore, instead of using \tag, use #eq- label immediately after an equation to not only enable equation numbering for this equation but also make it cross referencable and it will work across different formats. Read this section from Quarto docs for a detailed example.
---
title: XXX
author: "wananchi"
date: "`r Sys.Date()`"
format:
docx:
fontfamily: libertinus
fontsize: 11pt
toc: false
number-sections: true
# editor: visual
# bibliography: citations.bib
# csl: apa.csl
---
$$
ES_{w,t} = \varepsilon_wEP_{w,t}\
$${#eq-test}

Adding Escaped Quotes to Highcharts label

I want to add the clickable telephone numbers to a High Charts Organizational Chart.
The data for each text box looks like:
nodes: [{
id: 'CEO',
title: 'The Boss',
name: 'Jo Bloggs',
},{
I tried to escape the " marks with &#39 but that did not help, i.e.:
nodes: [{
id: 'CEO',
title: 'The Boss',
name: '<a href=&#39tel: 123456&#39>Jo Bloggs</a>',
},{
Consider use the Unicode Character 'QUOTATION MARK' (U+0022) \u0022.
Example:
nodes: [{
id: 'CEO',
title: 'The Boss',
name: '<a href=\u0022tel: 123456\u0022>Jo Bloggs</a>',
},{
See working jsfiddle and check the value Employee - Torstein Hønsi:
Example:
{
id: 'CPO',
title: 'CPO',
name: '<a href=\u0022#\u0022>Employee - Torstein Hønsi</a>',
image: 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2020/03/17131213/Highsoft_03998_.jpg'
}

Displaying GIF image from URL retrived as JSON array response

I am getting JSON array as response from external API which contains list of GIFs. Now I have the GIF URLs as part of this response which I want to show as images on Angular front end html page.
I tried iterating over the response using but that doesn't seem to work.
JSON response
0: {…}
​​​
analytics: Object { onload: {…}, onclick: {…}, onsent: {…} }
​​​
bitly_gif_url: "https://gph.is/YC1q17"
​​​
bitly_url: "https://gph.is/YC1q17"
​​​
content_url: ""
​​​
embed_url: "https://giphy.com/embed/6XeQfKBcO3K6c"
​​​
id: "6XeQfKBcO3K6c"
​​​
images: Object { fixed_height_still: {…}, original_still: {…}, fixed_width: {…}, … }
​​​
import_datetime: "1970-01-01 00:00:00"
​​​
is_sticker: 0
​​​
rating: "g"
​​​
slug: "hello-waving-movie-6XeQfKBcO3K6c"
source: ""
​​​
source_post_url: ""
​​​
source_tld: ""
​​​
title: "ryan gosling hello GIF"
​​​
trending_datetime: "2017-02-27 21:45:01"
​​​
type: "gif"
​​​
url: "https://giphy.com/gifs/hello-waving-movie-6XeQfKBcO3K6c"
​​​
username: ""
I just want the list of images (say 20) coming as response to be shown in row column mode in UI.
I got the actual GIF image URL by getting the complete JSON response details.
To display it simply calling the complete URL for the image,
<div class="gifs-card-container" *ngFor="let item of data">
<img src={{item.images.original.url}}>
</div>

How can I describe this JSON object in swagger parameters?

I've looked at a few other related questions and I still can't seem to find what I'm looking for. This is an example JSON payload being sent to an API I'm writing:
{
"publishType": "Permitable",
"electricalPanelCapacity": 0.0,
"roofConstruction": "Standard/Pitched",
"roofType": "Composition Shingle",
"systemConstraint": "None",
"addedCapacity": 0.0,
"isElectricalUpgradeRequired": false,
"cadCompletedBy": "94039",
"cadCompletedDate": "2017-02-01T02:18:15Z",
"totalSunhourDeficit": 5.0,
"designedSavings": 5.0,
"isDesignedWithinTolerance": "N/A",
"energyProduction": {
"january": 322.40753170051255,
"february": 480.61501312589826,
"march": 695.35215022905118,
"april": 664.506907341219,
"may": 877.53769491124172,
"june": 785.56924358327,
"july": 782.64347308783363,
"august": 760.1123565793057,
"september": 574.67050827435878,
"october": 524.53797441350321,
"november": 324.31132291046379,
"december": 280.46921069200033
},
"roofSections": [{
"name": "North East Roof 4",
"roofType": "Composition Shingle",
"azimuth": 55.678664773137086,
"tilt": 15.0,
"solmetricEstimate": 510.42831656979456,
"shadingLoss": 14.0,
"systemRating": 580.0,
"sunHours": 0.88004882167205956,
"moduleCount": 2,
"modules": [{
"moduleRating": 290.0,
"isovaPartNumber": "CDS-MON-007070",
"partCount": 2
}]
}, {
"name": "South West Roof 3",
"roofType": "Composition Shingle",
"azimuth": 235.67866481720722,
"tilt": 38.0,
"solmetricEstimate": 3649.1643776261653,
"shadingLoss": 59.0,
"systemRating": 5220.0,
"sunHours": 0.69907363556056812,
"moduleCount": 18,
"modules": [{
"moduleRating": 290.0,
"isovaPartNumber": "CDS-MON-007070",
"partCount": 18
}]
}, {
"name": "South East Roof",
"roofType": "Composition Shingle",
"azimuth": 145.67866477313709,
"tilt": 19.0,
"solmetricEstimate": 2913.1406926526984,
"shadingLoss": 31.0,
"systemRating": 2900.0,
"sunHours": 1.0045312733285168,
"moduleCount": 10,
"modules": [{
"moduleRating": 290.0,
"isovaPartNumber": "CDS-MON-007070",
"partCount": 10
}]
}],
"SystemConfiguration": {
"inverters": [{
"isovaPartNumber": "ENP-INV-007182",
"partCount": 30
}]
}
}
Describing all the beginning parameters was easy.
/post/new-cad/{serviceNumber}:
post:
summary: Publish a new CAD record.
description: Creates a new CAD record under the provided service number and returns the name of the new CAD record, the unique SF ID, and the deep link URL for Salesforce.
parameters:
- name: serviceNumber
in: path
description: The service number for the solar project you're interested in publishing to.
required: true
type: string
- name: publishType
in: formData
description: The type of CAD record to publish (Proposal, Permitable, or AsBuilt).
required: true
type: string
- name: electricalPanelCapacity
in: formData
required: true
type: number
format: double
- name: roofConstruction
in: formData
description: New, Flat Roof, Open Beam, Standard/Pitched
required: true
type: string
- name: roofType
in: formData
description: Composition Shingle, Membrane (Rubber, TPO, PVC, EPDM), Metal - Corrugated (S-Curve), Metal - Standing Seam, Metal - Trapezoidal, Multi Roof Type, Rolled Comp, Silicone, Tar & Gravel, Tile - Flat, Tile - S-Curve, or Tile - W-Curve
type: string
- name: systemConstraint
in: formData
description: Usage, None, Roof, Electrical, Shading, or 10kW Max
required: true
type: string
- name: addedCapacity
in: formData
required: true
type: number
format: double
- name: isElectricalUpgradeRequired
in: formData
type: boolean
- name: cadCompletedBy
in: formData
description: Employee ID of record author.
type: number
required: true
- name: cadCompletedDate
in: formData
description: The date the CAD record was completed.
type: string
format: date
required: true
- name: totalSunhourDeficit
in: formData
type: number
format: double
- name: designedSavings
in: formData
type: number
format: double
- name: isDesignedWithinTolerance
in: formData
type: string
description: Yes, No, or N/A
And yields the expected result in Swagger-UI:
But now I'm struggling with the last parts of the example JSON payload above. I'm unsure how to express the energyProduction key which is an object with a key for each month of the year. I'm also unsure how to describe roofSections which is an array of objects and systemConfiguration which is an object with a property inverters whose value is an array of objects.
I'm going over the swagger documentation quite a bit but I'm still pretty confused and hoping maybe someone here can explain things a little better to me.
I figured it out. Turns out formData is not what I should have been using for my parameters. Instead I needed to use body and define the structure of the JSON that would populate the body. Here is the completed design file using a body parameter with an object schema and describes all the nested objects and arrays as well.
/new-cad/{serviceNumber}:
post:
summary: Publish a new CAD record.
description: Creates a new CAD record under the provided service number and returns the name of the new CAD record, the unique SF ID, and the deep link URL for Salesforce.
parameters:
- name: serviceNumber
in: path
description: The service number for the solar project you're interested in publishing to.
required: true
type: string
- name: cadData
in: body
description: A JSON payload containing the data required to publish a new CAD record.
required: true
schema:
type: object
properties:
publishType:
type: string
default: "Proposal"
enum: ["Proposal","Permitable","AsBuilt"]
electricalPanelCapacity:
type: number
roofConstruction:
type: string
default: "New"
enum: ["New","Flat Roof","Open Beam","Standard/Pitched"]
roofType:
type: string
enum: ["Composition Shingle","Membrane (Rubber, TPO, PVC, EPDM)","Metal - Corrugated (S-Curve)","Metal - Standing Seam","Metal - Trapezoidal","Multi Roof Type","Rolled Comp","Silicone","Tar & Gravel","Tile - Flat","Tile - S-Curve","Tile - W-Curve"]
systemConstraint:
type: string
default: "None"
enum: ["None","Usage","Roof","Electrical","Shading","10kW Max"]
addedCapacity:
type: number
default: 0
isElectricalUpgradeRequired:
type: boolean
cadCompletedBy:
type: string
cadCompletedDate:
type: string
totalSunhourDeficit:
type: number
designedSavings:
type: number
isDesignedWithinTolerance:
type: string
default: "N/A"
enum: ["N/A","Yes","No"]
energyProduction:
type: object
properties:
january:
type: number
february:
type: number
march:
type: number
april:
type: number
may:
type: number
june:
type: number
july:
type: number
august:
type: number
september:
type: number
october:
type: number
november:
type: number
december:
type: number
roofSections:
type: array
items:
type: object
properties:
name:
type: string
roofType:
type: string
enum: ["Composition Shingle","Membrane (Rubber, TPO, PVC, EPDM)","Metal - Corrugated (S-Curve)","Metal - Standing Seam","Metal - Trapezoidal","Multi Roof Type","Rolled Comp","Silicone","Tar & Gravel","Tile - Flat","Tile - S-Curve","Tile - W-Curve"]
azimuth:
type: number
tilt:
type: number
solmetricEstimate:
type: number
shadingLoss:
type: number
systemRating:
type: number
sunHours:
type: number
moduleCount:
type: integer
modules:
type: array
items:
type: object
properties:
moduleRating:
type: number
isovaPartNumber:
type: string
partCount:
type: integer
systemConfiguration:
type: object
properties:
inverters:
type: array
items:
type: object
properties:
isovaPartNumber:
type: string
partCount:
type: integer
tags:
- NEW-CAD
responses:
200:
description: CAD record created successfully.
schema:
type: object
properties:
cadName:
type: string
sfId:
type: string
sfUrl:
type: string
examples:
cadName: some name
sfId: a1o4c0000000GGAQA2
sfUrl: http://some-url-to-nowhere.com
204:
description: No project could be found for the given service number.
500:
description: Unexpected error. Most likely while communicating with Salesforce.
schema:
type: string
So now I can still get the serviceNumber from the path while everything else comes in the request body. One thing to keep in mind here is that you cannot use all the same Swagger Data Types. For example I tried to use double for one of the properties and Swagger complained that it couldn't parse type double. I was very confused until I finally found the section of the docs describing the difference between formData parameters and a body parameter (of which you can only have one, because it describes the entire request body). Basically you can only use data types that are supported by the JSON schema.
Swagger-UI now shows a single textarea instead of multiple input fields for each parameter. Not as pretty but it works great. You can click the "Example Value" box on the right and it places a predefined JSON template in the textarea for you so you can just fill in the values.
If you are just learning Swagger like I am I hope this helps!

How to spread number of instances across availability zones in heat?

I have an instance resource along these lines:
masters:
type: OS::Heat::ResourceGroup
properties:
count: { get_param: num_masters }
resource_def:
type: heat_stack_server.yaml
properties:
name:
str_replace:
template: cluster_id-k8s_type-%index%
params:
cluster_id: { get_param: cluster_id }
k8s_type: master
cluster_env: { get_param: cluster_env }
cluster_id: { get_param: cluster_id }
type: master
image: { get_param: master_image }
flavor: { get_param: master_flavor }
key_name: { get_resource: keypair }
net: { get_resource: net }
subnet: { get_resource: subnet }
secgrp:
- { get_resource: master-secgrp }
- { get_resource: node-secgrp }
floating_network: { get_param: external_net }
net_name:
str_replace:
template: openshift-ansible-cluster_id-net
params:
cluster_id: { get_param: cluster_id }
depends_on:
- interface
It creates num_masters. Now, I want to guarantee these masters will be created in different availability zones (so that when one of them fails, the other will continue to work).
Say, I have 3 AZ and num_masters == 5. How to spread them, so that zone1 contains nodes 1 and 4, zone2 - 2 and 5, and so on?
Ansible has that loop.cycle thing where you could pass over a list of options over and over. Any ideas how to do it in OS?
OK, I found a solution. I see that someone ticked my question up, so I understand that there's someone else searching for a solution, so I'd better share mine.
You rarely use (and I certainly don't) Heat in isolation from other Configuration Management frameworks. I use it alongside Ansible. So in order to spread nodes between availability zones (AZ) you may consider to prepare this spread yourself. First, I have in my Ansible vars file a list of all AZ available (sorry for the pun):
zones:
- 'zone1'
- 'zone2'
Alternatively, you can query Openstack for that list. When you have it, you fill it into the environment file of your stack like this:
{% set zone_cycler = cycler( *zones ) %}
master_availability_zones: [{% for n in range(1,master_number+1) %}"{{ zone_cycler.next() }}"{% if not loop.last %}{{','}} {% endif %}{% endfor %}]
So for five hosts and two zones you'll get this:
master_availability_zones: ["zone1","zone2","zone1","zone2","zone1"]
Then you pass this list into your host resource group like this:
master_availability_zones:
type: comma_delimited_list
label: Master Availability zones
description: Availability zone mapping for masters
master_nodes:
type: OS::Heat::ResourceGroup
properties:
count: { get_param: master_number }
resource_def:
type: master_template.yaml
properties:
...
availability_zones: { get_param: master_availability_zones }
index: "%index%"
...
Don't forget to pass along index variable as well, you'll need it on the other side, in master_template.yaml:
master_node:
type: OS::Nova::Server
properties:
...
availability_zone: { get_param: [ availability_zones, { get_param: index } ] }
...
Voila, you now have scalable procedure accomodating for arbitrary host and zone numbers.