Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add sitemaps #14

Closed
Logmytech opened this Issue Dec 5, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@Logmytech
Copy link
Contributor

commented Dec 5, 2017

I'm adding a sitemaps file and making a pull request or in the existing pull request.

Sitemap allows easy crawling of site by search engines thereby boosting SEO and traffic.
It's a good practice to add site map.

Including a sitemaps.py file which generates the site is a good idea. It is entirely optional.

The app runs even without any of the steps, but sitemaps won't work.
The following steps are required for sitemap generation of djeddit threads.

Note that get_absolute_url() is required for sitemap.
I have added get_absolute_url in the slug pull request

I will try to add docs for including sitemap in main site.

You need to add the following apps in the installed apps list

    'django.contrib.sites',
    'django.contrib.sitemaps',

Here is my sitemaps.py file in the djeddit app.
@EatEmAll Please add this file in the djeddit app. It is entirely optional for users to use this sitemap.
Note that you need get_absolute_url() to get the absolute url in the Thread model.

from django.contrib.sitemaps import Sitemap

from .models import Thread

class ThreadSitemap(Sitemap):
    changefreq = "daily"
    priority = 0.7

    def items(self):
        return Thread.objects.all()

    def lastmod(self, obj):
        return obj.op.modified_on

Here is my urls.py file in the main project.

from django.contrib.sitemaps.views import sitemap

from djeddit.sitemaps import ThreadSitemap

sitemaps = {
    'djeddit' : ThreadSitemap
}

urlpatterns +=     url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'),

I have tested it and it works.

Here is my sitemap.xml file

<urlset><url><loc>http://127.0.0.1:8000/repon/dvfsd_g/1/fd-gdfgdfg-fd</loc><lastmod>2017-12-02</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url><url><loc>http://127.0.0.1:8000/repon/dvfsd_g/2</loc><lastmod>2017-12-02</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url></urlset>
@Logmytech

This comment has been minimized.

Copy link
Contributor Author

commented Dec 5, 2017

Added sitemap docs in the branch I made a pull request to.

Still need to figure out a way to ping google every 1 or two hours when sitemap is updated.

django.contrib.sitemaps.ping_google

@Logmytech

This comment has been minimized.

Copy link
Contributor Author

commented Dec 13, 2017

@EatEmAll You removed the get_absolute_url() function and made it relativeurl, but in django get_absolute_url is used by sitemaps and many other apps.

It may seem like relative url but in django it is called get_absolute_url()

Sitemaps are not working. I am going to add get_absolute_url in my pull request.

@EatEmAll

This comment has been minimized.

Copy link
Owner

commented Dec 29, 2017

@Logmytech Hmm, I didn't know that. I'll add them back in my next commit.

@EatEmAll

This comment has been minimized.

Copy link
Owner

commented Dec 29, 2017

@Logmytech I've added get_absolute_url() for Topic and Thread models in this commit:
https://github.com/EatEmAll/django-djeddit/commit/766977efbd0f956640f41753e91eba84caef2c88
Since you're more familiar than me with sitemaps I suggets that you'll test if sitemaps is working in this build.

@Logmytech Logmytech closed this Aug 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.