Add open graph data to the wiki and other pages

This commit is contained in:
Oliver Marks 2018-09-15 08:52:50 +01:00
parent 9c23136214
commit 83c71485db
10 changed files with 74 additions and 17 deletions

View File

@ -4,7 +4,10 @@
[[https://pyup.io/repos/github/maidstone-hackspace/maidstone-hackspace-website/][https://pyup.io/repos/github/maidstone-hackspace/maidstone-hackspace-website/shield.svg]] [[https://pyup.io/repos/github/maidstone-hackspace/maidstone-hackspace-website/][https://pyup.io/repos/github/maidstone-hackspace/maidstone-hackspace-website/shield.svg]]
Repository for the maidstone hackspace website, feel free to fork this site for your own Hackspace. Repository for the maidstone hackspace website, feel free to fork this site for your own Hackspace.
** Social
Test site sharing links / cards with twitter and facebook
https://cards-dev.twitter.com/validator
https://developers.facebook.com/tools/debug/
** Requirements ** Requirements
Before getting started make sure you have git, docker and docker-compose installed on your machine. Before getting started make sure you have git, docker and docker-compose installed on your machine.
The simplest way to setup this site is to use docker-compose so please install that from this site The simplest way to setup this site is to use docker-compose so please install that from this site

View File

@ -22,6 +22,7 @@ APPS_DIR = ROOT_DIR.path('mhackspace')
env = environ.Env() env = environ.Env()
env.read_env('%s/.env' % ROOT_DIR) env.read_env('%s/.env' % ROOT_DIR)
# Start ST is Spirit forum software config
ST_TOPIC_PRIVATE_CATEGORY_PK = 1 ST_TOPIC_PRIVATE_CATEGORY_PK = 1
ST_RATELIMIT_ENABLE = True ST_RATELIMIT_ENABLE = True
ST_RATELIMIT_CACHE_PREFIX = 'srl' ST_RATELIMIT_CACHE_PREFIX = 'srl'
@ -49,6 +50,8 @@ ST_UPLOAD_FILE_ENABLED = True
# Tests helpers # Tests helpers
ST_TESTS_RATELIMIT_NEVER_EXPIRE = False ST_TESTS_RATELIMIT_NEVER_EXPIRE = False
ST_BASE_DIR = os.path.dirname(__file__) ST_BASE_DIR = os.path.dirname(__file__)
# END ST is Spirit forum software config
SECRET_KEY = env('DJANGO_SECRET_KEY', default='wq)sg12k&5&adv)e%56n5e97o@))6xu90b**=-w+)d^c+cd9%1') SECRET_KEY = env('DJANGO_SECRET_KEY', default='wq)sg12k&5&adv)e%56n5e97o@))6xu90b**=-w+)d^c+cd9%1')

View File

@ -121,8 +121,8 @@ STATIC_URL = '%s/%s/' % (AWS_S3_ENDPOINT_URL, AWS_STORAGE_BUCKET_NAME)
# COMPRESSOR # COMPRESSOR
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
#COMPRESS_ENABLED = env.bool('COMPRESS_ENABLED', default=True) COMPRESS_ENABLED = env.bool('COMPRESS_ENABLED', default=True)
#COMPRESS_STORAGE = STATICFILES_STORAGE COMPRESS_STORAGE = STATICFILES_STORAGE
DEBUG_TOOLBAR_CONFIG = { DEBUG_TOOLBAR_CONFIG = {
'INTERCEPT_REDIRECTS': False, 'INTERCEPT_REDIRECTS': False,
} }

View File

@ -23,8 +23,10 @@ from mhackspace.blog.sitemaps import PostSitemap, CategorySitemap
from mhackspace.feeds.views import FeedViewSet, ArticleViewSet from mhackspace.feeds.views import FeedViewSet, ArticleViewSet
from mhackspace.requests.views import RequestsForm, RequestsList, RequestsDetail, RequestsDetailForm from mhackspace.requests.views import RequestsForm, RequestsList, RequestsDetail, RequestsDetailForm
from mhackspace.rfid.views import DeviceViewSet, AuthUserWithDeviceViewSet from mhackspace.rfid.views import DeviceViewSet, AuthUserWithDeviceViewSet
from mhackspace.core.views import ChatView, AboutView
from mhackspace.register.views import RegisterForm from mhackspace.register.views import RegisterForm
from mhackspace.wiki.urls import CustomWikiUrlPatterns
from wiki.urls import get_pattern as get_wiki_pattern from wiki.urls import get_pattern as get_wiki_pattern
from django_nyt.urls import get_pattern as get_nyt_pattern from django_nyt.urls import get_pattern as get_nyt_pattern
@ -47,8 +49,8 @@ sitemaps = {
urlpatterns = [ urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name='home'), url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name='home'),
url(r'^about/$', TemplateView.as_view(template_name='pages/about.html'), name='about'), url(r'^about/$', AboutView.as_view(template_name='pages/about.html'), name='about'),
url(r'^chat/$', TemplateView.as_view(template_name='pages/chat.html'), name='chat'), url(r'^chat/$', ChatView.as_view(template_name='pages/chat.html'), name='chat'),
url(r'^mailing-list/$', TemplateView.as_view(template_name='pages/mailing-list.html'), name='group'), url(r'^mailing-list/$', TemplateView.as_view(template_name='pages/mailing-list.html'), name='group'),
url(r'^contact/$', contact, name='contact'), url(r'^contact/$', contact, name='contact'),
@ -110,7 +112,7 @@ urlpatterns = [
urlpatterns += [ urlpatterns += [
url(r'^notifications/', get_nyt_pattern()), url(r'^notifications/', get_nyt_pattern()),
url(r'^wiki/', get_wiki_pattern(), name='wiki') url(r'^wiki/', get_wiki_pattern(url_config_class=CustomWikiUrlPatterns), name='wiki')
] ]
if settings.DEBUG: if settings.DEBUG:
# This allows the error pages to be debugged during development, just visit # This allows the error pages to be debugged during development, just visit

View File

@ -19,6 +19,7 @@ class BlogPost(DetailView):
"image": self.object.image, "image": self.object.image,
"title": self.object.title, "title": self.object.title,
"type": "blog", "type": "blog",
"description": self.object.excerpt,
} }
return context return context

View File

@ -6,21 +6,24 @@ from mhackspace.contact.forms import ContactForm
def contact(request): def contact(request):
form_class = ContactForm form_class = ContactForm
if request.method == 'POST': if request.method == "POST":
form = form_class(data=request.POST) form = form_class(data=request.POST)
if form.is_valid(): if form.is_valid():
data = form.cleaned_data data = form.cleaned_data
email = EmailMessage( email = EmailMessage(
'[%s] - %s' % (data['enquiry_type'], data['subject']), "[%s] - %s" % (data["enquiry_type"], data["subject"]),
data['message'], data["message"],
data['contact_email'], data["contact_email"],
to=['contact@maidstone-hackspace.org.uk'], to=["contact@maidstone-hackspace.org.uk"],
headers={'Reply-To': data['contact_email']}) headers={"Reply-To": data["contact_email"]},
)
email.send() email.send()
messages.add_message(request, messages.INFO, 'E-Mail sent') messages.add_message(request, messages.INFO, "E-Mail sent")
else: else:
form = form_class() form = form_class()
return render(request, 'pages/contact.html', { return render(
'form': form, request,
}) "pages/contact.html",
{"form": form, "open_graph": {"title": "Contact Us", "type": "article"}},
)

23
mhackspace/core/views.py Normal file
View File

@ -0,0 +1,23 @@
from django.views.generic import TemplateView
class ChatView(TemplateView):
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
context["open_graph"] = {
"title": "Chat with us",
"type": "website",
"description": "Speak to members of the Hackspace directly.",
}
return context
class AboutView(TemplateView):
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
context["open_graph"] = {
"title": "About Us",
"type": "article",
"description": "Useful information about Maidstone Hackspace.",
}
return context

View File

@ -32,7 +32,10 @@
<meta property="og:title" content="Maidstone Hackspace{% if open_graph.title %} - {{open_graph.title}}{% endif %}" /> <meta property="og:title" content="Maidstone Hackspace{% if open_graph.title %} - {{open_graph.title}}{% endif %}" />
<meta property="og:type" content="{% if open_graph.type %}{{open_graph.type}}{% else %}website{% endif %}" /> <meta property="og:type" content="{% if open_graph.type %}{{open_graph.type}}{% else %}website{% endif %}" />
<meta property="og:url" content="{{ request.build_absolute_uri }}" /> <meta property="og:url" content="{{ request.build_absolute_uri }}" />
<meta property="og:image" content="{% if open_graph.image %}{{open_graph.image.full.url}}{% else %}https://maidstone-hackspace.org.uk/static/images/android-chrome-192x192.png{% endif %}" /> <meta property="og:image" content="{% if open_graph.image %}{{open_graph.image.full.url}}{% else %}{% static 'images/android-chrome-192x192.png' %}{% endif %}" />
{% if open_graph.description %}
<meta property="og:description" content="{{open_graph.description}}" />
{% endif %}
{% endblock head-open-graph %} {% endblock head-open-graph %}

6
mhackspace/wiki/urls.py Normal file
View File

@ -0,0 +1,6 @@
from wiki.urls import WikiURLPatterns
from mhackspace.wiki.views import WikiArticleView
class CustomWikiUrlPatterns(WikiURLPatterns):
article_view_class = WikiArticleView

13
mhackspace/wiki/views.py Normal file
View File

@ -0,0 +1,13 @@
from wiki.views.article import ArticleView
class WikiArticleView(ArticleView):
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
context["open_graph"] = {
"image": "", # self.article.image,
"title": self.article.current_revision.title,
"type": "article",
"description": self.article.current_revision.content,
}
return context