Giter Site home page Giter Site logo

Comments (9)

hoosan avatar hoosan commented on August 17, 2024 6

I have run into the same "tofu" issue with Japanese characters and got stuck for a while.
As @r0mflip mentioned, adding the Noto family was the way to go.
I share the procedure in case someone is in the same trouble.

  1. Put a font file (e.g. *.otf) in "_fonts" directory.
    image

  2. Read the font file in template.ts

const noto = readFileSync(`${__dirname}/../_fonts/NotoSansJP-Black.otf`).toString('base64');

image

  1. Inject it to CSS
    @font-face {
        font-family: 'Noto Sans Japanese';
        font-style: normal;
        font-weight: normal;
        src: url(data:font/otf;charset=utf-8;base64,${noto}) format('opentype');
    }
  1. Add its font family name to the heading class
    .heading {
        font-family: 'Inter', 'Noto Sans Japanese', sans-serif;
        font-size: ${sanitizeHtml(fontSize)};
        font-style: normal;
        color: ${foreground};
        line-height: 1.8;
    }

That's it. It works fine most of the time.

image

An unresolved issue is that the some characters are still not visible.

image

But If I double the character ("あ" in this case), the problem has gone.

image

Dunno why.. I will try to add some more font files and see how it goes.

from og-image.

r0mflip avatar r0mflip commented on August 17, 2024 1

Not all fonts support all scripts. Some of the suggested ones would be to use from the Noto family, but even then it doesn't include CJK, Devanagri, Arabic, ...

If #70 works then it would be awesome that we can the required font and tweak the CSS a bit to support the required script. IMHO all-in-one solution might be a far fetch.

from og-image.

styfle avatar styfle commented on August 17, 2024

Hi @ryanckulp

We haven't tried posting in non-english languages since all our content is English at this time.

This could be related to #70.

from og-image.

ryanckulp avatar ryanckulp commented on August 17, 2024

update.. after 10 hours i'm almost. there.

tldr -- replaced puppateer w/ selenium-webdriver.

one question about Zeit server config: what's the executable path i should be using for Chrome, in prod?

tried: /tmp/chromium // /usr/local/bin/chromedriver

the latter works locally but not in production, says "PATH NOT FOUND."

from og-image.

styfle avatar styfle commented on August 17, 2024

ZEIT Now doesn't ship Chrome so you would have to consult the docs for selenium-webdriver to find out where it installs Chrome for Linux. If you can set a path, I would suggest /tmp because that is the only writable directory on the filesystem.

from og-image.

AntwanSherif avatar AntwanSherif commented on August 17, 2024

@ryanckulp Could you share with me how did you solve this issue? Also it it applicable for Arabic language for example?

from og-image.

tomy0000000 avatar tomy0000000 commented on August 17, 2024

I want to point out that even though most of us can get around with this problem by injecting Noto fonts in to HTML templates for now, the true issue here is actually lies within the chrome-aws-lambda.

I did some experiment:

  • Try running on my local dev: worked -> which means the currently provided fonts is fine.
  • Deployed on Vercel: failed -> Something happened on the cloud went wrong.
  • Deployed another instance with OG_HTML_DEBUG=1 envs: worked -> The render html can properly display, which leaves the only possibility to the screenshot function.

from og-image.

ryanckulp avatar ryanckulp commented on August 17, 2024

@tomy0000000 thanks for the fix! really appreciate it.

from og-image.

leerob avatar leerob commented on August 17, 2024

Closing in favor of #226

from og-image.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.