<script type="application/javascript">
appendHtml = function(element, html) {
var div = document.createElement('div');
div.innerHTML = html;
while (div.children.length > 0) {
element.appendChild(div.children[0]);
}
};
{% if settings.product is defined and settings.product.seo is defined %}
{% set seo = settings.product.seo %}
{% set original_resource = settings.product %}
{% endif %}
{% if settings.taxon is defined and settings.taxon.seo is defined %}
{% set original_resource = settings.taxon %}
{% set seo = settings.taxon.seo %}
{% endif %}
appendHtml(document.head, '<meta name="twitter:card" content="summary"></meta>');
appendHtml(document.head, '<meta name="og:type" content="website" />');
{% if seo is defined and seo is not null %}
{% if seo.image is not null %}
{% set source_image_path = seo.image.path %}
{% set original_image_path = source_image_path|imagine_filter('sylius_shop_seo_image') %}
{% endif %}
{% if seo.pageTitle %}
document.title = '{{ seo.pageTitle }}';
{% endif %}
{% if seo.twitterSite is not empty %}
appendHtml(document.head, '<meta name="twitter:site" content="{{ seo.twitterSite|e('js') }}" />');
{% endif %}
{% if seo.twitterTitle is not empty %}
appendHtml(document.head, '<meta name="twitter:title" content="{{ seo.twitterTitle|e('js') }}" />');
{% else %}
appendHtml(document.head, '<meta name="twitter:title" content="{{ original_resource.name|e('js') }}" />');
{% endif %}
{% if seo.twitterDescription is not empty %}
appendHtml(document.head, '<meta name="twitter:description" content="{{ seo.twitterDescription|e('js') }}" />');
{% else %}
appendHtml(document.head, '<meta name="twitter:description" content="{{ original_resource.description|e('js') }}" />');
{% endif %}
{% if seo.ogTitle is not empty %}
appendHtml(document.head, '<meta name="og:title" content="{{ seo.ogTitle|e('js') }}" />');
{% else %}
appendHtml(document.head, '<meta name="og:title" content="{{ original_resource.name|e('js') }}" />');
{% endif %}
{% if seo.ogDescription is not empty %}
appendHtml(document.head, '<meta name="og:description" content="{{ seo.ogDescription|e('js') }}" />');
{% else %}
appendHtml(document.head, '<meta name="og:description" content="{{ original_resource.description|e('js') }}" />');
{% endif %}
{% if original_image_path is defined %}
appendHtml(document.head, '<meta name="og:image" content="{{ original_image_path }}" />');
{% endif %}
{% if seo.extraTags is not empty %}
appendHtml(document.head,'{{ seo.extraTags|e('js') }}');
{% endif %}
{% else %}
appendHtml(document.head, '<meta name="twitter:title" content="{{ original_resource.name|e('js') }}" />');
appendHtml(document.head, '<meta name="twitter:description" content="{{ original_resource.description|e('js') }}" />');
appendHtml(document.head, '<meta name="og:title" content="{{ original_resource.name|e('js') }}" />');
appendHtml(document.head, '<meta name="og:description" content="{{ original_resource.description|e('js') }}" />');
{% endif %}
</script>