配置Hugo从DB内容生成网站

发布于 2025-01-29 16:24:30 字数 71 浏览 2 评论 0原文

Hugo中是否有一个插件或其他内容允许Hugo从DB读取内容并生成站点,而不是从Markdown/Data Files读取数据?

Is there a plugin or something in Hugo that allows hugo to read content from DB and generate site, rather than reading data from markdown/data files?

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

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

发布评论

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

评论(1

陈年往事 2025-02-05 16:24:30

开箱即用,雨果仅生成html(或XML,或JSON)表示您的Markdown文件。雨果哲学中有一些东西说可再现的建筑优先于其他事物 - 我不知道我在哪里看过,但是当我在寻找同一件事时,我已经看到了它。

但是有一些方法可以使您更接近这一点。

transform.unmarshall

parses jsontomlyamlxmlcsv资源>资源和转换它们可以地图或阵列。但是您仍然需要一个本地文件来使用它。

您可以做的一件事是将其递增到您的构建工作流中, 您使用雨果生成网站,您将添加一个步骤来获取数据并将其写入其中一个中的本地文件格式。

resources.getRemote

Resources.getRemote 向远程URL提出http请求,最近已添加到Hugo中。

这样,您就无需在构建过程中迈出新的步骤即可抓取,格式化和将数据写入磁盘。相反,您会在模板中添加一些逻辑以从URL获取数据。当然,您需要HTTP端点,因此您仍然需要某种API。

Out of the box, Hugo only generates HTML (or XML, or JSON) representations of your Markdown files. There's something in Hugo's philosophy that says that reproducible builds take precedence over other things — I don't know where I've seen, but I have seen it at some point, when I was looking for the same thing you are.

But there are some ways to get you closer to that.

transform.unmarshall

transform.unmarshal parses JSON, TOML, YAML, XML, or CSV resources and converts them to maps or arrays. But you still need a local file to use it.

One thing that you could do is to incroporate this into your build workflow and before you generate your site with Hugo, you would add a step to grab the data and write it to a local file in one of those formats.

resources.GetRemote

resources.GetRemote makes an HTTP request to a remote URL, and has recently been added to Hugo.

This way, you wouldn't need to have a new step in the build process to grab, format, and write data to the disk; you would instead, add some logic in your templates to grab the data from a URL. Of course, you need that HTTP endpoint, so you still need some sort of API available.

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