14

我正在尝试在我的 Phoenix 应用程序中使用自定义字体。我已将它们放在priv/static/fonts目录中,并在模板中正确创建并加载了 css 文件,web/templates/layout/app.html.eex但 Phoenix 服务器没有为它们提供服务。

/Users/Psycho/code/elixir/my_app/
▾ priv/
  ▸ repo/
  ▾ static/
    ▸ css/
    ▾ fonts/
      ▾ walsheim/
          gt-walsheim-light-web.svg
          gt-walsheim-light-web.eot
          gt-walsheim-light-web.ttf
          gt-walsheim-light-web.woff

用于采购字体的 css 文件:

// my_app/priv/css/fonts.css

@font-face {
    font-family: "Walsheim";
    font-style: normal;
    font-weight: 300;
    src:
        url("/fonts/walsheim/gt-walsheim-light-web.eot?#iefix") format("embedded-opentype"),
        url("/fonts/walsheim/gt-walsheim-light-web.woff") format("woff"),
        url("/fonts/walsheim/gt-walsheim-light-web.ttf") format("truetype"),
        url("/fonts/walsheim/gt-walsheim-light-web.svg#Walsheim") format("svg");
}
4

1 回答 1

22

好的,找到了解决方案。

看起来你必须告诉phoenix哪些目录为静态文件服务。我进入我的my_app/lib/my_app/endpoint.ex文件并更新了Plug.Static插件以服务于该fonts文件夹:

defmodule MyApp.Endpoint do
  use Phoenix.Endpoint, otp_app: :my_app

  plug Plug.Static,
    at: "/", from: :my_app, gzip: false,
    only: ~w(css images js fonts favicon.ico robots.txt)

  # Other Stuff ...
end

来源:PhoenixTalk - 在子文件夹中提供静态资产而不是默认值

于 2015-07-12T01:45:30.660 回答