Giter VIP home page Giter VIP logo

image-sitemaps's Introduction

image-sitemaps

Google image sitemaps for Django. More informations about image sitemaps on Google Webmaster Tools.

Installation

You can get image-sitemaps from pypi with:

pip install django-image-sitemaps

The development version can be installed with:

pip install -e git://github.com/akarzim/image-sitemaps#egg=image-sitemaps

image-sitemaps introduce a new XML template therefore you should add it to your INSTALLED_APPS in settings.py:

INSTALLED_APPS = (
    ...
    'imagesitemaps',
    ...
)

Usage

Create a new file named sitemaps.py in your app directory and declare your ImageSitemap classes :

# -*- coding: utf-8 -*-
from django.core.urlresolvers import reverse
import imagesitemaps

class ImageSitemap(imagesitemaps.ImageSitemap):
    """ generic data for all ours image sitempas (use it as you used to with Django Sitemap) """  
    changefreq = 'weekly'
    priority = 0.5

    def lastmod(self, obj):
        return obj.modified

class ProductImageSitemap(ImageSitemap):
    """ a specific image sitemap for ours Product class """
    
    def items(self):
        """ Django Sitemap's items method """
        return Product.objects.all()

    def images(self, obj):
        """ this method allows you to define multiple images for an object """
        return obj.images()

    def image_loc(self, img):
        """ this required method define the image location """
        return img.doc.url

    def image_caption(self, img):
        """ this optional method define the image caption """
        return unicode(img)


    def location(self, obj):
       """ Django Sitemap's location method """
        return reverse(
            'webstore_product',
            kwargs={
                'slug_product': obj.slug,
            }
        )

Then you have to add this data at the end of your Django root urls.py :

from myapp.sitemaps import ProductImageSitemap

imagesitemaps = {
    'products': ProductImageSitemap,
}

urlpatterns += patterns('imagesitemaps.views',
    url(r'^sitemap-image\.xml$', 'index', {'sitemaps': imagesitemaps}),
    url(r'^sitemap-image-(?P<section>.+)\.xml$', 'sitemap', {'sitemaps': imagesitemaps}),
)

Image tag definitions

Tag Required Description
<image:image> Yes Encloses all information about a single image. Each URL (<loc> tag) can include up to 1,000 <image:image> tags.
<image:loc> Yes The URL of the image.

In some cases, the image URL may not be on the same domain as your main site. This is fine, as long as both domains are verified in Webmaster Tools. If, for example, you use a content delivery network (CDN) to host your images, make sure that the hosting site is verified in Webmaster Tools OR that you submit your Sitemap using robots.txt. In addition, make sure that your robots.txt file doesn’t disallow the crawling of any content you want indexed.

<image:caption> Optional The caption of the image.
<image:geo_location> Optional The geographic location of the image. For example, <image:geo_location>Limerick, Ireland</image:geo_location>.
<image:title> Optional The title of the image.
<image:license> Optional A URL to the license of the image.

If we want to declare a new tag in our image sitemap (i.e. <image:license>), we just have to define a new method starting with image_ in our ImageSitemap class :

class ProductImageSitemap(ImageSitemap):
    ...
    def image_license(self, license):
        """ this optional method define the image license """
        return u"http://creativecommons.org/licenses/by-nd/3.0/legalcode"

image-sitemaps's People

Contributors

amrhassan avatar akarzim avatar

Watchers

James Cloos avatar Mohamed Nabil Hafez avatar Ahmed Gaber avatar Saifeldein Mohamed avatar Moamen Hmad avatar Ali Allam avatar Ahmed Elshahawi avatar Mostafa Sabry avatar Mostafa Gomaa avatar Muhammad Aref avatar mahmoudnabil avatar Ahmed Alwerdani avatar mostafa avatar Tamer Sherif avatar mahmoud farid avatar Omar Saber Talaat Abddelrahman avatar Ahmed Abdalgaber avatar  avatar Ahmed Abodeif avatar Afnan Elnomrosy avatar Hesham Elkhatib avatar Ahmed Abdelhak avatar

Forkers

elcodo

image-sitemaps's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.