utils.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:wagtail-schema.org 作者: takeflight 项目源码 文件源码
def image_ld(image, thumbnail_filter="max-200x200", base_url=None):
    # Support custom image models with a to_json_ld() method
    if hasattr(image, 'to_json_ld'):
        return image.ld_entity()

    thumbnail = image.get_rendition(thumbnail_filter)
    url = urljoin(base_url, image.file.url)

    return {
        '@context': 'http://schema.org',
        '@type': 'ImageObject',
        '@id': url,
        'name': image.title,
        'url': url,
        'contentUrl': url,
        'contentSize': str(image.file.size),
        'width': Distance('{} px'.format(image.width)),
        'height': Distance('{} px'.format(image.height)),
        'thumbnail': urljoin(base_url, thumbnail.url),
    }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号