from django.conf import settings
from django.contrib.staticfiles import views

from django.contrib import admin
from django.urls import path, re_path, include
from django.views.generic.base import RedirectView
from django.contrib.sitemaps.views import sitemap

from core import views as core
from blog.sitemaps import BlogSitemap, CategorySitemap, PageSitemap, StaticViewSitemap

# Configuration du sitemap dynamique
sitemaps = {
    'blog': BlogSitemap,
    'categories': CategorySitemap,
    'pages': PageSitemap,
    'static': StaticViewSitemap,
}

urlpatterns = [
	path('tinymce/', include('tinymce.urls')),  # Réactivé
	path('admin/', admin.site.urls),

	path('favicon.ico', RedirectView.as_view(url = '/static/favicon.ico')),

	# Sitemap dynamique (remplace /static/sitemap.xml)
	path('sitemap.xml', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'),

	# HTTP 410 Gone pour les anciennes URLs /youtube/ et /flux/
	# Ces URLs causaient des erreurs Soft 404 (13 pages)
	# Indique à Google que ces ressources n'existent plus définitivement
	re_path(r'youtube/(?P<path>.*)$', core.gone_view),
	re_path(r'flux/(?P<path>.*)$', core.gone_view),
	re_path(r'lecture_flux/(?P<path>.*)$', core.gone_view),

	path('blog/', include('blog.urls')),

	
	path('', RedirectView.as_view(url = 'blog/')),
	path('' , core.index, name='core_index'),
	# url generique
	re_path(r'page/(?P<p_url>[a-zA-Z0-9_,-/]+)', core.page, name='core_page'),
	# last chance 
	re_path(r'(?P<p_url>[a-zA-Z0-9_.,-]+)', core.page, name='core_page'),

]

if settings.DEBUG:
	urlpatterns += [
		re_path(r'^static/(?P<path>.*)$', views.serve),
	]
