从数据库字段生成.md文件

发布于 2025-01-28 18:44:43 字数 970 浏览 2 评论 0原文

对于一个学校项目,我正在使用Hugo Static网站生成器进行网络商店。我在.md文件中有商店的产品。我还拥有一个带有名为,价格,价格,描述等的名为产品的表格的数据库,并带有管理页面,因此管理员可以在数据库中添加新产品。现在的问题是,我需要以某种方式使用数据库信息为新产品生成.md文件。我的想法是将已经存在的.MD文件用于产品,然后通过搜索和替换,插入新产品的信息。但是我不知道如何意识到这一点。感谢任何帮助。谢谢! 这是一个已经放映的产品.md文件的示例

---
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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似狗非友 2025-02-04 18:44:43

几个月前,我确实面临着同样的问题。我创建一个MD文件的模板,如下所示。然后,我运行一个脚本(我选择Python,但是您可以使用任何语言)。它读取数据库,打开模板,用相应的值替换所有%%参数%%,然后将MD文件存储在您想要的位置。

---
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%%"

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%%"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文