only include indexable posts in sitemap.xml

This commit is contained in:
rimu 2025-01-23 16:06:49 +13:00
parent c8c325ceed
commit 2967956cc5
2 changed files with 3 additions and 9 deletions

View file

@ -465,14 +465,8 @@ def robots():
@bp.route('/sitemap.xml')
@cache.cached(timeout=6000)
def sitemap():
posts = Post.query.filter(Post.from_bot == False, Post.deleted == False)
posts = posts.join(Community, Community.id == Post.community_id)
posts = posts.filter(Community.show_all == True, Community.ap_id == None) # sitemap.xml only includes local posts
if not g.site.enable_nsfw:
posts = posts.filter(Community.nsfw == False)
if not g.site.enable_nsfl:
posts = posts.filter(Community.nsfl == False)
posts = posts.order_by(desc(Post.posted_at))
posts = Post.query.filter(Post.from_bot == False, Post.deleted == False, Post.instance_id == 1, Post.indexable == True)
posts = posts.order_by(desc(Post.posted_at)).limit(100)
resp = make_response(render_template('sitemap.xml', posts=posts, current_app=current_app))
resp.mimetype = 'text/xml'

View file

@ -1,4 +1,4 @@
<h3>{% if post.sticky -%}<span class="fe fe-sticky-left"></span>{% endif -%}<a href="{{ url_for('activitypub.post_ap', post_id=post.id, sort='new' if sort == 'active' else None) }}" class="post_teaser_title_a">{{ post.title }}</a>
<h3>{% if post.sticky -%}<span class="fe fe-sticky-left"></span>{% endif -%}<a href="{{ url_for('activitypub.post_ap', post_id=post.id, sort='new' if sort == 'active' else None) }}" class="post_teaser_title_a" {% if not post.indexable %}rel="noindex"{% endif %} >{{ post.title }}</a>
{% if post.type == POST_TYPE_IMAGE -%}
<span class="fe fe-image" aria-hidden="true"> </span>
{% endif -%}