Убрал лишнее из sitemap
parent
ecf383f020
commit
2fc695e335
|
@ -0,0 +1,34 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 5e6d181b4b74
|
||||
Revises: e24055e16b26
|
||||
Create Date: 2023-10-04 08:46:50.473590
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '5e6d181b4b74'
|
||||
down_revision = 'e24055e16b26'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('page', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('update_datetime', sa.DateTime(), nullable=True))
|
||||
batch_op.create_unique_constraint(None, ['id'])
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('page', schema=None) as batch_op:
|
||||
batch_op.drop_constraint(None, type_='unique')
|
||||
batch_op.drop_column('update_datetime')
|
||||
|
||||
# ### end Alembic commands ###
|
|
@ -71,9 +71,3 @@ def get_posts_for_sitemap():
|
|||
.all()
|
||||
)
|
||||
return posts
|
||||
|
||||
|
||||
def get_pages_for_sitemap():
|
||||
pages = db.session.query(Page.slug).all()
|
||||
date = datetime.utcnow().strftime("%Y-%m-%d")
|
||||
return pages, date
|
||||
|
|
|
@ -102,3 +102,8 @@ class Page(db.Model):
|
|||
name = Column(String(20))
|
||||
slug = Column(String(50), nullable=False)
|
||||
text = Column(Text)
|
||||
update_datetime = Column(
|
||||
DateTime(),
|
||||
default=func.now(),
|
||||
onupdate=func.now(),
|
||||
)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from flask import make_response, render_template
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from pyproger.dbase.database import get_pages_for_sitemap, get_posts_for_sitemap
|
||||
from pyproger.dbase.database import get_posts_for_sitemap
|
||||
|
||||
from .robots import bp
|
||||
|
||||
|
@ -9,12 +9,9 @@ from .robots import bp
|
|||
@bp.route("/sitemap.xml", methods=["GET"])
|
||||
def sitemap_xml():
|
||||
sm_posts = get_posts_for_sitemap()
|
||||
sm_pages, date = get_pages_for_sitemap()
|
||||
sm_render = render_template(
|
||||
"robots/sitemap.xml",
|
||||
sm_pages=sm_pages,
|
||||
sm_posts=sm_posts,
|
||||
date=date,
|
||||
)
|
||||
response = make_response(sm_render)
|
||||
response.headers["Content-Type"] = "application/rss+xml"
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
|
||||
{% for p in sm_posts %}
|
||||
<url>
|
||||
<loc>http://www.pyproger.ru/post/{{ p.slug }}</loc>
|
||||
|
|
Loading…
Reference in New Issue