Tumblr非常令人印象深刻,因为它允许我直接发布到博客中。不过,我也想为推特卡添加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] ? />发布于 2015-07-28 01:40:33
Tumblr不支持将任意元数据添加到帖子中,但您可以通过重用Tumblr中已经存储的内容并添加适当的meta标记,将您想要的Tumblr元素添加到为访问者提供的博客帖子输出中。
转到Tumblr、您的帐户、您的Tumblr博客、“编辑外观”、“编辑主题”、“编辑HTML",添加一个只在post页面上执行的输出块:
<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>您需要为每个post类型添加额外的{block:Something} Tumblr模板标签。此示例只支持链接帖子。
https://stackoverflow.com/questions/31662836
复制相似问题