在雨果网站中使用Tw-elements

发布于 2025-02-10 08:47:33 字数 237 浏览 1 评论 0原文

我想在雨果网站上添加旋转木马,所以我试图使用Tw-elements。我已经使用了他们的快速启动指南,然后将TW-Elements插件放入插件部分tailwind-config.js文件,但脚本未导出到公共文件夹。有人做过吗?我想念什么步骤? 谢谢!

I want to add a carousel in a Hugo site, so I'm trying to use tw-elements. I have used their quick start guide and put the tw-elements plugin in the plugins section of the tailwind-config.js file, but the script isn't exported to the public folder. Has anyone done this before? What step(s) am I missing?
Thanks!

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

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

发布评论

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

评论(2

ま柒月 2025-02-17 08:47:33

仅将tailwind-config.js文件放在雨果中就不够了。您需要:

  1. 生成style.css使用Assets/static/目录中的tailwind
  2. 将链接放在样式中。 CSS由Tailwind生成的雨果(例如< head></head>部分,例如在baseof.html模板中。

请参阅此处,以获取有关将Hugo与Tailwind集成的完整指南:
https://www.unsungngovelty.org/posts/03/2022/how-to-to-to-x-add-tailwind-css-3-to-a-a-a-hugo-website-in-20222/

noreferrer “ 通过将以下行放入< head></head>部分:

<script src="https://cdn.tailwindcss.com"></script>

Just putting the tailwind-config.js file in Hugo won't be enough. You need to:

  1. generate a style.css using Tailwind in your assets/ or static/ directory
  2. put a link to the style.css generated by Tailwind into Hugo, for example in <head></head> section, for example in the baseof.html template.

See here for a complete guide on integrating Hugo with Tailwind:
https://www.unsungnovelty.org/posts/03/2022/how-to-add-tailwind-css-3-to-a-hugo-website-in-2022/

An alternative is to use Tailwind CDN by putting the following line in the <head></head> section of your site:

<script src="https://cdn.tailwindcss.com"></script>
刘备忘录 2025-02-17 08:47:33

使用命令行首次设置项目

#bash
hugo new site your-website-name
cd your-website-name

使用雨果创建自己的主题

#bash
hugo new theme your-theme-name
激活您的主题:在您的根部打开Hugo.toml(或Hugo.yaml)文件Hugo站点并添加或更新主题配置:在FrontMatter中添加此
theme = "your-theme-name"
package.json使用
npm init -y

install tailwindcss及其同行依赖性通过NPM创建您的tailwind.config .js文件。

npm install -D tailwindcss postcss autoprefixer postcss-import

因此,现在我们必须在我们的主题目录和一个样式中创建tailwind和Postcss配置文件。CSS文件,该文件充当CSS输出文件

touch themes/your-theme-name/assets/css/postcss.config.js
touch themes/your-theme-name/assets/css/tailwind.config.js
touch themes/your-theme-name/assets/css/style.css

现在,让我们配置我们的Postcss配置文件,以便打开PostCSSS 。

const themeDir = __dirname + '/../../';
// here __dirname is current working directory where postcss.config.js file loacted.
module.exports = {    
    plugins: [   
        require('postcss-import')({
            path: [themeDir]
            }), 
        require('tailwindcss')(themeDir + 'assets/css/tailwind.config.js'),
        require('autoprefixer')({
            path: [themeDir]
        }),
    ]
}

const themeDir = __dirname + "/../../";
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [`${themeDir}/layouts/**/*.html`, `${themeDir}/content/**/*.md`],
  theme: {
    extend: {},
  },
  plugins: [],
};


打开我们以前创建的

@tailwind base;
@tailwind utilities;
@tailwind components;

在Head Tag中导入CSS的style.CSS文件
当我们创建新主题时,Hugo通过创建一些启动模板文件来帮助我们。这些入门文件之一是head.html部分。

此文件的位置您的website-name/themes/your-theme-name/layouts/partials

添加此行head.html文件,元标记

{{ $time := now }} 
{{ $styles := resources.Get "css/styles.css" 
    | postCSS (dict"config" "./assets/css/postcss.config.js") 
    | resources.ExecuteAsTemplate (printf "styles.%s.css" $time) 
    $time 
  }} 

{{ if hugo.IsServer }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" />
{{ else }} {{ $styles := $styles | minify | fingerprint | resources.PostCSS }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" />
{{ end }}

现在转到baseof.html文件在Body标签中添加一些HTML元素
并使用尾风类。

您的website-name/content文件夹中创建一些标记文件,请访问该页面,查看您的页面是否看起来像baseof.html文件,

如果遇到任何错误,可能是由于错别字,无论是从您的身边还是我的。检查拼写,如果发生其他错误,请在评论中告诉我。

First set-up your project using command line

#bash
hugo new site your-website-name
cd your-website-name

Create your own theme using hugo

#bash
hugo new theme your-theme-name
Activate Your Theme: Open the hugo.toml (or hugo.yaml) file in the root of your Hugo site and add or update the theme configuration: Add this in frontmatter
theme = "your-theme-name"
Now initailize package.json file using
npm init -y

Install tailwindcss and its peer dependencies via npm, and create your tailwind.config.js file.

npm install -D tailwindcss postcss autoprefixer postcss-import

So, now we have to create tailwind and postcss config file in our theme directory and one style.css file which is act as css output file

touch themes/your-theme-name/assets/css/postcss.config.js
touch themes/your-theme-name/assets/css/tailwind.config.js
touch themes/your-theme-name/assets/css/style.css

Now let's configure our postcss config file so open up postcss.config.js

const themeDir = __dirname + '/../../';
// here __dirname is current working directory where postcss.config.js file loacted.
module.exports = {    
    plugins: [   
        require('postcss-import')({
            path: [themeDir]
            }), 
        require('tailwindcss')(themeDir + 'assets/css/tailwind.config.js'),
        require('autoprefixer')({
            path: [themeDir]
        }),
    ]
}

Now let's configure our tailwind config file so open up tailwind.config.js

const themeDir = __dirname + "/../../";
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [`${themeDir}/layouts/**/*.html`, `${themeDir}/content/**/*.md`],
  theme: {
    extend: {},
  },
  plugins: [],
};

Add the Tailwind directives to your CSS:
open up style.css file that we created previously

@tailwind base;
@tailwind utilities;
@tailwind components;

Importing CSS in head tag
When we created our new theme, Hugo helped us out by creating some starting templates files. One of these starter files is the head.html partial.

location of this file your-website-name/themes/your-theme-name/layouts/partials

Add this line head.html file after meta tag

{{ $time := now }} 
{{ $styles := resources.Get "css/styles.css" 
    | postCSS (dict"config" "./assets/css/postcss.config.js") 
    | resources.ExecuteAsTemplate (printf "styles.%s.css" $time) 
    $time 
  }} 

{{ if hugo.IsServer }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" />
{{ else }} {{ $styles := $styles | minify | fingerprint | resources.PostCSS }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" />
{{ end }}

Now go to baseof.html file add some html element inside body tag
and use tailwind class.

create some markdown file in your-website-name/content folder visit that page see if your page is look like baseof.html file with some content of your markdown file or not

If you encounter any errors, it may be due to typos, either from your side or mine. Check spelling and if any other error happen please let me know in comment.

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