Sitemap generator for Python frameworks
Project description
Dynamic sitemap
master | dev |
---|---|
A simple sitemap generator for Python projects.
Already implemented:
- metaclass SitemapMeta
- FlaskSitemap
Installation
- using pip
pip install dynamic-sitemap
or
- as a git submodule
git submodule add -b master --name sitemap https://github.com/KazakovDenis/dynamic-sitemap path/to/app/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')
sitemap.config.IGNORED.update(['/edit', '/upload'])
sitemap.config.TEMPLATE_FOLDER = ['app', 'templates']
sitemap.update()
sitemap.add_rule('/blog', Post, lastmod='created')
sitemap.add_rule('/blog/tag', Tag, priority=0.4)
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_rule('/goods', Product, slug='id', lastmod='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
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
Built Distribution
Close
Hashes for dynamic_sitemap-0.1.0a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d428dc5b97c6ec79661279db0aa8979d743880e27b3a42abf5663951a4d69550 |
|
MD5 | 71be4909089fc07b44761a95201d2a64 |
|
BLAKE2b-256 | 60bce15aec4330c87f58a0b02f296d4078608fb5a095fd224f1fcbc3cdadac11 |