如何向Tumblr API的博客标题添加元标签?

3
非常强大,它允许我直接发布博客。然而,我想为Twitter卡片添加meta。有没有什么方法可以实现这一点?
       client = pytumblr.TumblrRestClient(
            app.config['CONSUMER_KEY'],
            app.config['CONSUMER_SECRET'],
            app.config['OAUTH_TOKEN'],
            app.config['OAUTH_SECRET'],
        )
        if news.is_published:
            body = ''
            if news.image_url_list and len(news.image_url_list) > 0:
                body = '<img src="{0}" /><br/>'.format(news.image_url_list[0])
            slug = Slugify.slugify(news.head_line)
            post = client.create_text("xxx.tumblr.com",
                                      state="published",
                                      tags=news.tag_list,
                                      format='html',
                                      slug=slug,
                                      title=news.head_line,
                                      body=body + news.summary.encode('utf-8'))

我该如何将这些元标签添加到博客文章中?

<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@flickr" />
<meta name="twitter:title" content=? news.head_line ? />
<meta name="twitter:description" content=? news.description ? />
<meta name="twitter:image" content=? news.image_url_list[0] ? />

1
你能提供一个 [mcve] 吗? - boardrider
1个回答

1
Tumblr API 不支持向帖子添加任意元数据,但您可以通过重用已存储在Tumblr中的内容并添加适当的Tumblr标记来向访问者提供所需的 HTML元素。
前往Tumblr,进入您的帐户和Tumblr博客,“编辑外观”,“编辑主题”,“编辑HTML”,然后添加一个仅在帖子页面上执行的输出块。
<html>
    <head>
        <!-- ... -->

        <!-- Only show on permalink pages (blog post) -->
        {block:PostTitle}
            <!-- Iterate over all post types -->
            {block:Posts}
                <!-- For Link posts, output this -->
                {block:Link}
                    <meta name="twitter:card" content="summary" />
                    <meta name="twitter:site" content="@example" />
                    <meta name="twitter:title" content="{Name}" />
                    <meta name="twitter:description" content="{Description}" />
                    <meta name="twitter:image" content="{Thumbnail-HighRes}" />
                {/block:Link}
            {/block:Posts}
        {/block:PostTitle}

        <!-- ... -->
    </head>
    <body>
        <!-- ... -->
    </body>
</html>

您需要为每种帖子类型添加额外的{block:Something}Tumblr模板标签。这个例子只支持链接帖子。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接