Skip to content

Commit

Permalink
Use sitemap django app
Browse files Browse the repository at this point in the history
  • Loading branch information
Clément committed Jul 17, 2024
1 parent 1b67b84 commit d0ba4d6
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 7 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ COPY common-content/ common-content/
COPY galae-content/ galae-content/

# Build
RUN ./manage.py migrate
RUN npm run build \
&& ./manage.py distill-local --collectstatic --force dist

Expand Down
2 changes: 1 addition & 1 deletion content/templates/jinja2/allwidgets.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div class="navbar__container__right">
<a class="btn btn-sm btn-primary" href="{{ CTA_URL }}"
target="{{ CTA_TARGET }}">{{ CTA_LABEL }}</a>
<a href="{{ url('page', args=[CHANGE_LANG_URL]) }}">
<a href="{{ url_for_slug_path(CHANGE_LANG_URL) }}">
<img class="languageFlag" src="{{ static(CHANGE_LANG_FLAG_URL)}}" alt="{{ CHANGE_LANG_ALT }}"/>
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion content/templates/jinja2/sitemap.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% endfor %}
{% for p in object.posts_slugs %}
<url>
<loc>{{ object.domain }}/pages/{{ p }}.html</loc>
<loc>{{ object.domain }}/posts/{{ p }}.html</loc>
</url>
{% endfor %}

Expand Down
7 changes: 5 additions & 2 deletions jssg/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,23 @@
runserver.default_addr = '127.0.0.1'

# JSSG
JFME_DOMAIN = "https://www.galae.net"
JFME_DOMAIN = "www.galae.net"
JFME_CONTENT_DIRS = [BASE_DIR / "content"] + [BASE_DIR / "galae-content"] + [BASE_DIR / "common-content"]
JFME_PAGES_DIRS = [path / "pages" for path in JFME_CONTENT_DIRS]
JFME_POSTS_DIRS = [path / "posts" for path in JFME_CONTENT_DIRS]
JFME_TEMPLATES_DIRS = [path / "templates" for path in JFME_CONTENT_DIRS]
JFME_STATIC_DIRS = [path / "static" for path in JFME_CONTENT_DIRS]


#Django sites and sitemap app
SITE_ID = 1

# Application definition

INSTALLED_APPS = [
"jssg",
"django.contrib.contenttypes",
"django.contrib.sites",
"django.contrib.sitemaps",
"whitenoise.runserver_nostatic",
"django.contrib.staticfiles",
"django_distill",
Expand Down
28 changes: 28 additions & 0 deletions jssg/sitemaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import Any
from django.contrib.sitemaps import Sitemap
from django.contrib.sites.models import Site
from jssg.models import Page, Post
from django.conf import settings

class MySitemap(Sitemap) :
def get_urls(self, site=None, **kwargs):
site = Site(domain=settings.JFME_DOMAIN, name=settings.JFME_DOMAIN)
return super(MySitemap, self).get_urls(site=site, **kwargs)

class PageSitemap(MySitemap) :
def items(self) :
return list(Page.load_glob(all = True))
def location(self, page) -> str:
if page.rel_folder_path != '' :
return "/" + page.rel_folder_path + "/" + page.slug + ".html"
else :
return "/" + page.slug + ".html"

class PostSitemap(MySitemap) :
def items(self) :
return list(Post.load_glob(all = True))
def location(self, page) -> str:
if page.rel_folder_path != '' :
return "/posts/article/" + page.rel_folder_path + "/" + page.slug + ".html"
else :
return "posts/articles/" + page.slug + ".html"
7 changes: 5 additions & 2 deletions jssg/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from jssg.models import Page, Post
from jssg import settings

from django.contrib.sitemaps.views import sitemap
from jssg.sitemaps import PageSitemap, PostSitemap

# print([p for p in Page.get_pages()])

Expand Down Expand Up @@ -53,7 +55,8 @@
),
distill_path(
"sitemap.xml",
views.SitemapView.as_view(),
name = "sitemap"
sitemap,
{"sitemaps": {"page": PageSitemap, "posts": PostSitemap}},
name="django.contrib.sitemaps.views.sitemap",
)
]
19 changes: 18 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,24 @@
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"paths": {
"@/*": [
"./*"
],
"@s:jssg/*": [
"./jssg/static/jssg/*"
],
"@t:jssg/*": [
"./jssg/templates/jssg/*"
],
"@s:django_distill/*": [
"./env/lib/python3.9/site-packages/django_distill/static/django_distill/*"
],
"@t:django_distill/*": [
"./env/lib/python3.9/site-packages/django_distill/templates/django_distill/*"
]
}
},
"include": [
"content/front/"
Expand Down

0 comments on commit d0ba4d6

Please sign in to comment.