Generate .md files from database fields - database

for a school project I am making a webshop with the Hugo static website generator. And I have the products of the shop in .md files. I also have a database with a table called product with name, price, description etc with an admin page so the admin can add new products to the database. The problem now is that I somehow need to generate a .md file for the new product using the database information. My idea was to use an already existing .md file for a product and via search and replace, insert the information for the new product. But I have no clue how to realize that. I would appreciate any help. Thanks!
Heres an example for an already exisiting product .md file
---
title: "Baklava"
date: 2019-10-17T11:22:16+06:00
draft: false
# meta description
description : ""
# product Price
price: "22.00"
beforeprice: ""
# Product Short Description
shortDescription: ""
#product ID
productID: "4"
#Gramm
name: "Wie viel Gramm?"
amount: "400g|700g[+6.00]|1000g[+10.00]"
# type must be "products"
type: "products"
# product Images
# first image will be shown in the product page
images:
- image: "images/products/Produkt 5/Unbenannt.png"
---
Eine Mischung an Baklava von bester Qualität. Sie haben die Möglichkeit die verschiedenen Spezialitäten vorort zu probieren und sich selbst zu überzeugen. Lassen Sie sich von einer Mischung an feinsten Baklavasorten überraschen.

I did face the same problem a few months ago. I create a template of MD file, like below. Then, I run a script (I choose Python, but you can use any language). It reads the database, open the template, replace all the %%PARAM%% by the corresponding values, and store the MD file where you want it.
---
title: "%%TITLE%%"
date: 2019-10-17T11:22:16+06:00
draft: false
# meta description
description : "%%DESCRIPTION%%"
# product Price
price: "%%PRICE%%"
beforeprice: ""
# Product Short Description
shortDescription: "%%SHORT_DESCRIPTION%%"

Related

firestore data model using multiple sub collections

I have a current structure in my firestore.
Data model:
- users (collection)
- 9d5UCo4RtyTosiFAIvnPK4zFCUk1 ( each user is a separate document )
- trips ( collection )
- New York (Document)
- fields: date, description, photos:[url1, url2, ....] ( fields in the New York document), status:public
- Los Angeles
....
Now I want to add notes, likes and metadata for each photo in the New York, LA, etc photos array.
I have a few ideas but not sure which is scalable and works well for what I want to do with notes, likes and metadata.
The notes don't have to load at the same time the photos do. The user would click to open notes which could be a new query to DB. But each photo does need to know how many notes are associated with each photo when photos are been displayed.
Solution 1:
photos array would be an object instead.
const photos = {
isdffd: {
url: "path",
likes: 100,
metadata: {
...
},
},
xxydfsd: {
url: `path`,
likes: 10,
metadata: {
...
}
},
};
Then I have a collection of notes back up where trips is and use the photo id as the id for the note. but that limits me to 1 note per photo which I want to be able to add multiple notes.
I also want to be able to build a search page which would search through all notes throughout all trips and display them grouped by trip in the results.
What would be a good approach for this kind of setup with what I have right now which is using sub-collections for most of my structure so far.
Solution 2:
add another sub-collection inside each trip document called photos
each photo would be its own document with likes, metadata and notes. But then notes needs to be a sub-collection of each photo document. This would make it hard to search all trips and all notes for each photo.
The way your original function has been structured:
- users (collection)
- 9d5UCo4RtyTosiFAIvnPK4zFCUk1 ( each user is a separate document )
- trips ( collection )
- New York (Document)
- fields: date, description, photos:[url1, url2, ....] ( fields in the New York document), status:public
- Los Angeles
....
If you implement the first solution, you will limit your code if in the future you want to add another field to the photos object, or as you add additional photos to the object.
Adding a photos sub-collection inside your trips is your best option, this way your collection can grow and avoid the limitation of the first solution (having to make any change manually). If your notes are only text, then you can keep them inside each photo document as an array, avoiding another subcollection. Keeping the photos as a sub-collection and keeping the URL, likes, metadata and notes (if they are only text) inside each photo created should not add much difficulty when querying.

Hugo content not rendering

I've used the hugo-icon single page theme to build a static site and have been asked to add a new page for product descriptions. I have read many tutorials/answers on stack and watched Mike Danes videos to date but cannot get a new page to render.
When I run the following command hugo new products/product1/_index.md a url to product1 is generated but no content is rendered. This is the content of my _index.md file;
---
title: "Product1"
date: 2021-05-24T14:47:36+01:00
draft: false
---
product1 info
I expect one of 2 things; To see 'product1 info' rendered at the url. OR I place a html file of the same name somewhere in the folder structure to render text etc. I have tried multiple locations to place html and still I cannot see anything.
Can someone explain or give an example of adding a new page to the hugo-icon theme and explain if I am missing a fundamental concept.
config:
# Main config file for icon theme.
theme = ["hugo-icon"]
baseURL = "https://www.example.com/"
languageCode = "en-ie"
title = "my site"
[params]
author = "Me"
description = "My site"
# Hero section (from here on is for icon theme)
[params.hero]
img = "images/hero_bg_green.jpg"
title = "My Site"
Thanks
I was missing this fundamental design pattern. Each folder created under layouts required a template. In my case this looked like the following where each page was designed inside the single.html file
Layouts
page1
single.html
page2
single.html
The route needs defining in the content folder inside content/pages/page-one.md like so where type is mapped to the folder name by its type definition
type : "page1"
title: "Page 1"
date: 2021-05-27T11:16:39+01:00
draft: false
My url therefore is www.example.com/pages/page-one.html which is designed in layouts/page1/single.html and mapped via the type definition to www.example.com/content/pages/page-one.md
The .md file inside content/... dictates the path to the url. The type definition dictates which page to render from layouts/...

one block of text coming from database

I have put paragraphs of text into my mongo database using a mongoose schema. It is a lot of text and it just comes out as one giant block of text on my site page. I have tried including html into the paragraphs but it shows the html and remains as one giant blob of text.
My question is: how do I store paragraphs of text in my database and display them as separate paragraphs? Many thanks in advance.
name: 'Superstar Road Bike',
mainImage: '/public/img/Bikes/Road/Superstar Disc/Superstar.jpeg',
gallery: [ '/public/img/Bikes/Road/Superstar Disc/superstar bottom bracket.jpeg'
, '/public/img/Bikes/Road/Superstar Disc/superstar rear.jpeg'
, '/public/img/Bikes/Road/Superstar Disc/superstar front end.jpeg'
],
description: '<p>Superstar reinterprets at the highest degree of.</p>in carbon fiber, the legendary Italian competition bicycle on the track, the Cinelli that embodies the brands heritage and DNA.Unlike other brands that every year offer bicycles with an increasingly reduced use destination, Cinelli developed Superstar with a meticulous attention to how the intrinsic qualities of carbon fiber and the production processes could be used to create a tremendous edition contemporary of the legendary Italian Grand Tour quality in the saddle: an intelligent balance of lightness, perfect maneuverability on any surface and comfort over long distances.',
price: 39999,
salePrice: 400,
Here is how I am displaying it in my EJS file:
<div id="itemParagraph">
<p> <%= bike.description %> </p>
</div>
<div id="colorSeparator"></div>

Neos CMS: Avoid duplication content nodes in multilingual setup

I have a multilingual setup of Neos CMS 4.3.. When I create a new page I want to have it in all languages to keep the structure for all languages in sync.
But within the pages I want to be able to create a content node for just the current language. Is this possible?
When I create a content node and it exists afterwards in all languages I can even not delete it because it is going to be recreated.
I already searched the internet for other people who have this use case
and try to delete the content node in the language where I don't want to have it.
The content repository language dimension:
ContentRepository:
contentDimensions:
'language':
label: 'Language'
icon: icon-language
default: de
defaultPreset: de
presets:
all: null
'en_US':
label: 'English'
values:
- en_US
uriSegment: en
'de':
label: 'Deutsch'
values:
- de
uriSegment: de
I want to be able to be able to manage content within one page in different languages independently.

Wagtail StreamField not rendering in template after INSERT new row

I have a CMS based on wagtail, and have recently re-written it in a more sensible fashion. I have written a script to migrate the old content to this new version, which is based on wagtail 2.3 (old version was on wagtail 1.11). I have written the migration script (to re-construct various foreign keys etc) and all content has been populated and seems to be working except for the render of StreamFields.
Frustratingly, when I switch back to my test db for v2, this works fine (content is rendered) - I've been scouring my databases for differences between the two rows (in wagtailcore_page or blog_blogpostpage) and can't see any difference. There's obviously something I'm missing in the way wagtail fetches StreamField content, can anyone enlighten me as to what I might have missed in the migration? Many thanks!!
models.py
class BlogPostPage(Page): # Individual blog post
template = 'blog/post_page.html'
parent_page_types = ['blog.BlogIndexPage']
show_in_menus_default = True
author = models.ForeignKey(
User, on_delete=models.PROTECT, default=1,
)
description = models.CharField(
max_length=300, blank=False,
help_text="Add a brief (max 300 characters) description for this blog post."
)
date = models.DateField(
"Post date",
help_text="This date may be displayed on the blog post. "
"It is not used to schedule posts to go live at a later date."
)
body = StreamField([
('heading', blocks.CharBlock(classname="full title")),
('paragraph', blocks.RichTextBlock()),
('embed', EmbedBlock()),
('image', ImageChooserBlock(classname='img-responsive')),
('code', CodeBlock(label='Code')),
('table', TableBlock(label='Table'))
], help_text="Create content by adding new blocks.")
table blog_blogpostpage entry:
"page_ptr_id","description","date","body","author_id"
23,"Now including Blog!","2018-12-06","[{""type"": ""paragraph"", ""value"": ""<p>Since the first release we've made some improvements and upgrades...</p>"", ""id"": ""25fe32be-2090-42dd-8e3e-4df53c494227""}]",15
migration_script.sh
INSERT INTO "public"."wagtailcore_page"("path","depth","numchild","title","slug","live","has_unpublished_changes","url_path","seo_title","show_in_menus","search_description","go_live_at","expire_at","expired","content_type_id","owner_id","locked","latest_revision_created_at","first_published_at","live_revision_id","last_published_at","draft_title")
VALUES
(E'00010002000O0001',4,0,E'Release: version 2',E'release-version-2',TRUE,FALSE,E'/home/blog/release-version-2/',E'',TRUE,E'',NULL,NULL,FALSE,6,15,FALSE,E'2018-12-06 16:58:10.897348+08',E'2018-12-06 16:58:10.926032+08',NULL,E'2018-12-06 16:58:10.926032+08',E'Release: version 2');
INSERT INTO "public"."blog_blogpostpage"("page_ptr_id","description","date","body","author_id")
VALUES
((SELECT id FROM wagtailcore_page WHERE path='00010002000O0001'),E'Now including Blog!',E'2018-12-06',E'[{"type": "paragraph", "value": "<p>Since the first release we've made some improvements and upgrades...</p>", "id": "25fe32be-2090-42dd-8e3e-4df53c494227"}]',15);
template.html
{% include_block page.body %}
^^^ Nothing is shown for the page.body field, but description, date and author are rendered.
Your data migration created invalid JSON:
[{""type"": ""paragraph"", ""value"": ""<p>S ...
Should have single quotes:
[{"type": "paragraph", "value": "<p>S ...

Resources