Sitemap generator for Python frameworks
Project description
Dynamic sitemap
A simple sitemap generator for Python projects.
Already implemented:
- metaclass SitemapMeta
- FlaskSitemap
Installation
- using pip
pip install dynamic-sitemap
Usage
"Hello world" example:
from framework import Framework
from dynamic_sitemap import FrameworkSitemap
app = Framework(__name__)
sitemap = FrameworkSitemap(app, 'https://mysite.com')
sitemap.update()
Then run your server and visit http://mysite.com/sitemap.xml.
Basic example with some Models:
from framework import Framework
from dynamic_sitemap import FrameworkSitemap
from models import Post, Tag
app = Framework(__name__)
sitemap = FrameworkSitemap(app, 'https://mysite.com', orm='sqlalchemy')
sitemap.config.IGNORED.update(['/edit', '/upload'])
sitemap.config.TEMPLATE_FOLDER = 'templates'
sitemap.config.TIMEZONE = 'Europe/Moscow'
sitemap.update()
sitemap.add_elem('/faq', changefreq='monthly', priority=0.4)
sitemap.add_rule('/blog', Post, lastmod_attr='created', priority=1.0)
sitemap.add_rule('/blog/tag', Tag, changefreq='daily')
Also you can set configurations from your class (and it's preferred):
sm_logger = logging.getLogger('sitemap')
sm_logger.setLevel(30)
class Config:
TEMPLATE_FOLDER = os.path.join(ROOT, 'app', 'templates')
IGNORED = {'/admin', '/back-office', '/other-pages'}
ALTER_PRIORITY = 0.1
LOGGER = sm_logger
sitemap = FrameworkSitemap(app, 'https://myshop.org', config_obj=Config)
sitemap.add_elem('/about', changefreq='monthly', priority=0.4)
sitemap.add_rule('/goods', Product, loc_attr='id', lastmod_attr='updated')
Moreover you can get a static file by using:
sitemap.build_static()
Some important rules:
- use update() method after setting configuration attributes directly (not need if you pass your config object to init)
- use get_dynamic_rules() to see which urls you should add as a rule or to ignored
- config.IGNORED has a priority over add_rule
- use helpers.Model if your ORM is not supported
Not supported yet:
- urls with more than 1 converter, such as
/page/<int:user_id>/<str:slug>
Check out the Changelog
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dynamic-sitemap-0.1.0.dev2.tar.gz
(11.4 kB
view hashes)
Built Distribution
Close
Hashes for dynamic-sitemap-0.1.0.dev2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e4a3c7cc5069562bb26b41376336eba107885bf755ae0d8b002e958a6b902a1 |
|
MD5 | fc587ce7e2908107ecadaea6ddaeedd4 |
|
BLAKE2b-256 | ca69ae0aec8bab1c508045916dafa4178e060fb9d837c7e6c6afdbd3d7d5b5bd |
Close
Hashes for dynamic_sitemap-0.1.0.dev2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15b1915b548a0c790cb2e1b6de8081842ce33c4f3167188a7536ef872bfc5fb7 |
|
MD5 | 7c9740f31aedf2b3db670adbb5ee5510 |
|
BLAKE2b-256 | 5117ff49f4ddf30fc4bfa8152c4dfb5ceabb62ed93d959417dc9d4071c54c063 |