2017-08-26 3 views
0

私はこの問題に固執しています。Jekyllでbase64エンコーディングを行う方法

Jekyllの文字列をbase64にエンコードする方法はありますか?

Github Pagesにコードをプッシュする前または後に、ブログ内のすべての投稿にjsonファイルを作成したいと思います。

- 2017-08-26-post1.md 
- 2017-08-26-post1.md 

- 2017-08-26-post1.json 
- 2017-08-26-post1.json 

多分{{ some_string | base64_encoded }}

答えて

2

のようなものは、あなた自身の液体のタグを作成し、パラメータとして、あなたの文字列を指定することができます。その後、ruby https://ruby-doc.org/stdlib-2.1.3/libdoc/base64/rdoc/Base64.htmlを使ってその文字列をbase64に変換し、ページに出力します。このような何かが、私はここで見つける例だった、助けて

からhttps://blog.sverrirs.com/2016/04/custom-jekyll-tags.html:このことができます

class AdsInlineTag < Liquid::Tag 
    def initialize(tag_name, input, tokens) 
    super 
    @input = input 
    end 

    def render(context) 
    # Split the input variable (omitting error checking) 
    input_split = split_params(@input) 
    adclient = input_split[0].strip 
    adslot = input_split[1].strip 

    # Write the output HTML string 
    output = "<div style=\"margin: 0 auto; padding: .8em 0;\"><script async " 
    output += "src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\">" 
    output += "</script><ins class=\"adsbygoogle\" style=\"display:block\" data-ad-client=\"#{adclient}\"" 
    output += "data-ad-slot=\"#{adslot}\" data-ad-format=\"auto\"></ins><script>(adsbygoogle =" 
    output += "window.adsbygoogle || []).push({});</script></div>" 

    # Render it on the page by returning it 
    return output; 
    end 

    def split_params(params) 
    params.split("|") 
    end 
end 
Liquid::Template.register_tag('ads', AdsInlineTag) 

希望、私は試してみて、ジキルのためのシンプルなbase64で液体タグを作成し、私はそれを取得した場合に更新するだろうワーキング。

関連する問題