Skip to content

Commit

Permalink
增加global header,footer 配置
Browse files Browse the repository at this point in the history
  • Loading branch information
liangliangyy committed Mar 29, 2023
1 parent cdc03af commit 80b8b23
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
5 changes: 4 additions & 1 deletion blog/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def seo_processor(requests):
'ANALYTICS_CODE': setting.analyticscode,
"BEIAN_CODE_GONGAN": setting.gongan_beiancode,
"SHOW_GONGAN_CODE": setting.show_gongan_code,
"CURRENT_YEAR": timezone.now().year}
"CURRENT_YEAR": timezone.now().year,
"GLOBAL_HEADER": setting.global_header,
"GLOBAL_FOOTER": setting.global_footer,
}
cache.set(key, value, 60 * 60 * 10)
return value
23 changes: 23 additions & 0 deletions blog/migrations/0002_blogsettings_global_footer_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.1.7 on 2023-03-29 06:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('blog', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='blogsettings',
name='global_footer',
field=models.TextField(blank=True, default='', null=True, verbose_name='公共尾部'),
),
migrations.AddField(
model_name='blogsettings',
name='global_header',
field=models.TextField(blank=True, default='', null=True, verbose_name='公共头部'),
),
]
2 changes: 2 additions & 0 deletions blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ class BlogSettings(models.Model):
google_adsense_codes = models.TextField(
'广告内容', max_length=2000, null=True, blank=True, default='')
open_site_comment = models.BooleanField('是否打开网站评论功能', default=True)
global_header = models.TextField("公共头部", null=True, blank=True, default='')
global_footer = models.TextField("公共尾部", null=True, blank=True, default='')
beiancode = models.CharField(
'备案号',
max_length=2000,
Expand Down
5 changes: 4 additions & 1 deletion templates/share_layout/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<link rel='stylesheet preload' as="font" id='twentytwelve-fonts-css'
href='{% static 'blog/fonts/fonts.css' %}'
type='text/css' media='all'/>
<link rel="dns-prefetch" href="//cdn.mathjax.org" />
<link rel="dns-prefetch" href="//cdn.mathjax.org"/>
{% compress css %}

<link rel='stylesheet' id='twentytwelve-style-css' href='{% static 'blog/css/style.css' %}' type='text/css'
Expand All @@ -44,6 +44,9 @@
{% block compress_css %}
{% endblock %}
{% endcompress %}
{% if GLOBAL_HEADER %}
{{ GLOBAL_HEADER|safe }}
{% endif %}
</head>

<body class="home blog custom-font-enabled">
Expand Down
3 changes: 3 additions & 0 deletions templates/share_layout/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
{% if ANALYTICS_CODE %}
{{ ANALYTICS_CODE| safe }}
{% endif %}
{% if GLOBAL_FOOTER %}
{{ GLOBAL_FOOTER|safe }}
{% endif %}
</footer><!-- #colophon -->


0 comments on commit 80b8b23

Please sign in to comment.