• GitHub
  • Documentation
  • Discord
  • Tip
search
  • chevron_right Threads
  • label Dev Development

Misago Generator Sitemap (for 0.5)

testtesttest
July 22, 2014
chat_bubble_outline 4
  • link
    testtesttest
    Members 19 posts
    July 22, 2014, 10:50 a.m. July 22, 2014, 10:50 a.m.
    link
    1. Install GIT and libs. (Ubuntu)
      sudo apt-get install git
      sudo apt-get install python-MySQLdb

    2. To home.
      cd ~

    3. Executable command:
      git clone github.com/michal0468/misago-generate-sitemap

    4. To script.
      cd ~/misago-generate-sitemap

    5. Edit, and change data to database, and url to website.
      nano main.py

    6. Executable.
      python main.py

    7. Copy sitemap.xml to /static/ in misago.

    8. Entry in google webmasters:
      mysite.com/static/sitemap.xml

  • link
    rafalp
    Project Lead 2028 posts
    July 22, 2014, 1:34 p.m. July 22, 2014, 1:34 p.m.
    link

    It would fare much better as Django app, and what when you have thousands of threads? Loading them all into memory won't fly.

  • link
    testtesttest
    Members 19 posts
    July 22, 2014, 1:38 p.m. July 22, 2014, 1:38 p.m.
    link

    I couldn't make it otherwise.

  • link
    rafalp
    Project Lead 2028 posts
    July 22, 2014, 6:33 p.m. July 22, 2014, 6:33 p.m.
    link

    Its very simple actually. Make directory caled "misagositemaps", put __init__.py in it. Put directory into it, name it management. Put __init__.py in it. Finally inside that dir make commands directory. There make empty __init__.py and non-empty makesitemap.py.

    Writing manage.py commands is documented here. Here are example commands defined by Django, and here is command Misago uses to prune forums of old threads.

    For memory-safe iteration over threads, this command imports misago.models.Forum model and runs following:

    for forum in Forum.objects.iterator():
        for thread in forum.thread_set.all().iterator():
            # Thiss wont load all threads to memory and won't crash when you have many threads.
    

    Other issue I've spotted is that it includes private threads, reports as well as threads made in private forums in sitemap. However I admit that in lack of real documentation for 0.5 APIs, its going to be tricky to get it done "right" from nothing.

    So for starters add extra query to pull out lft and rght fields of forum with special="root". Then run second query pulling out ID's on forums that have lft greater than root's one and rght smaller than root's one. Those ID's will belong to forums.

    Lh4cKg and avi like this.

    favorite 2

  • link
    avi
    Members 24 posts
    Sept. 6, 2014, 7:23 p.m. Sept. 6, 2014, 7:23 p.m.
    link

    ^that code snippet looks so beautiful

    Hosenfeld likes this.

    favorite 1

arrow_upward Go to top
  • This site uses cookies to gather statistical data for use in traffic analysis.
  • GitHub
  • Documentation
  • Discord
  • Tip
  • Terms of service
  • Privacy policy
powered by misago