How to add themes/<theme name>/static/css to _partial/head.html?

I tried several days to make my own theme, it almost done, still a few problems.
Here is the one.

I put css files into themes/my-theme/static/css directory, for example:

themes/my-theme/static/css/section_number/section_number.css

and also have the following in partial/head.html

{{ if ne .Params.section_number  false }}
<link href="/css/section_number/section_number.css" rel="stylesheet" type="text/css">
{{ end }}

after hugo generate public files, I found that this part in page sources is:
and get a 404 error, but not the which works, has a “/” before “css”.

So, my question is how to add the themes//static/ things to head.html?

Thanks!

Have you tried using absURL or relURL

<link href="{{ "css/section_number/section_number.css" | absURL }}" rel="stylesheet" type="text/css">

@funkydan2, Thank you. but it seems not work, According to https://github.com/gohugoio/hugo/issues/5207, move mytheme/layout/static/css to mytheme/asset/

  {{ $section_number := resources.Get "css/section_number/section_number.css" }}
  <link href="{{ $section_number.Permalink }}" rel="stylesheet" type="text/css">
   {{ end }}

Now works.

There was a keyin mistake: I moved mytheme/static/css to mytheme/asset/ .

Sorry, I’d missed that. You can use the asset directory if you’re going to be processing assets (e.g. from scss to css). The static directory works for non-processed assets (its contents are copied straight to /public). However, not if it’s within your layouts folder.

/themes/mytheme/static/css/section_number.css will work. /themes/mytheme/layouts/static/css/section_number.css won’t.

@funkydan2 ,

Oops, it was a key in mistake, in fact I do have mytheme/static/css, but this do not work, I have to move the css to assets, mean while, mytheme/static/js works. Realy have no idea.

Thanks.

Well, I’m glad you got it working…but it should work in mytheme/static/css. (If you want it to work in static, feel free to post a link to your git repository, and someone might be able to see what’s gone wrong.)

Good idea, I think I can prepare a github repos.