gpt4 book ai didi

ubuntu - 如何将波斯字体添加到 Next.js?

转载 作者:行者123 更新时间:2023-12-04 18:40:12 25 4
gpt4 key购买 nike

我无法在 ubuntu 中将波斯字体添加到我的 Next.js 中,我的字体 url 是 :static/Fonts/IRANSansWeb.eot 。我使用了 dangerouslySetInnerHTML 但仍然无法在 ubuntu 中工作。我不明白为什么在 mac os 中工作

font URL
- 我在我的代码中试过这个:

return (
<html lang="en" dir="rtl">
<Head>
<title>فراخوان نقد</title>
<meta charSet="utf-8" />
{/* Use minimum-scale=1 to enable GPU rasterization */}
<meta
name="viewport"
content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no"
/>
{/* PWA primary color */}
<meta name="theme-color" content={pageContext.theme.palette.primary.main} />
{/* <link
rel="stylesheet"
href="https://fonts.googleapis.com/css?
family=Roboto:300,400,500"
/> */}
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-
alpha.6/css/bootstrap.min.css"
/>
<style dangerouslySetInnerHTML={{__html: `
@font-face {
font-family:
'IranSans,tahoma';
font-style:
normal;
font-weight:
400;
src:
url("../static/Fonts/IRANSansWeb.eot");
src:
url("../static/Fonts/IRANSansWeb.eot?#iefix")
format('embedded-opentype'),
url("../static/Fonts/IRANSansWeb.woff2")
format('woff2'),
url("../static/Fonts/IRANSansWeb.woff")
format('woff'),
url("../static/Fonts/IRANSansWeb.ttf")
format('truetype');
}
body{
font-family:
'IranSans, tahoma' !important
}
`}}/>
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
);

最佳答案

一种需要 的解决方案ontfaceobserver .
根据您的选择更改字体

字体.js

const FontFaceObserver = require('fontfaceobserver')

const Fonts = () => {
const link = document.createElement('link')
link.href = 'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900'
link.rel = 'stylesheet'

document.head.appendChild(link)

const roboto = new FontFaceObserver('Roboto')

roboto.load().then(() => {
document.documentElement.classList.add('roboto')
})
}

export default Fonts

然后在我的 index.js
import React from 'react'
import Home from '@/Home'
import Fonts from '~/general/Fonts'

class Index extends React.Component {
componentDidMount () {
Fonts()
}

render () {
return <Home />
}
}

export default Index

关于ubuntu - 如何将波斯字体添加到 Next.js?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52232411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com