Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    punch-fix-utf8public

    punch – fix-utf8 generator hook

    This generator hook will help you fix broken encoding when you generated some non HTML text file (i.e. xml, json…).

    Use-case

    I've met this case when trying to generate a rss.xml file using a content-handler, there's an issue for that but here is a "user-land" fix.

    This concerns every file generated from content handlers and not having .html extension, as punch will use binary encoding in those cases, and writing text with this encoding will result in iso-8859-1 files (your call, Node).

    Installation

    npm install punch-fix-utf8

    Usage

    In your config.json:

    {
        "plugins": {
            "generator_hooks": {
                "fix_utf8": "./fix-utf8-hook"
            }
        },
        "utf8_paths": [
            "/path/to/file.xml"
        ]
    }

    Just provide in utf8_paths the list of paths that should be re-encoded using utf8 encoding instead of binary.

    How does it work?

    This will simply fs.writeFile(…, fs.readFile(…, 'binary'), 'utf8').

    To avoid re-encoding to UTF-8 each time you regenerate your pages (which would break your files, again) a file named .fix_utf8 stores modified paths, and date of modification (so that re-generated files will be re-fixed). You can safely delete it only if you regenerate your whole project after that.

    Keywords

    none

    install

    npm i punch-fix-utf8

    Downloadslast 7 days

    0

    version

    2.0.2

    license

    none

    repository

    github.com

    last publish

    collaborators

    • avatar