Some basic support for gross SEO metadata formats with django-meta

This commit is contained in:
Danielle McLean 2017-10-24 21:57:07 +11:00
parent 1aed52b75f
commit 8ef64d6a87
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
8 changed files with 40 additions and 5 deletions

View file

@ -14,6 +14,7 @@ gunicorn = "*"
pillow = "*" pillow = "*"
python-memcached = "*" python-memcached = "*"
django-favicon-plus = "*" django-favicon-plus = "*"
django-meta = "*"
[dev-packages] [dev-packages]

9
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "388a82f0237a5312720d62a0aeee6365922fc525d666039e15ba70000430630c" "sha256": "60ee6c91a6c7b88c2a424a70428f3f380adc142716ebe82ce35f31a10cedeb3c"
}, },
"host-environment-markers": { "host-environment-markers": {
"implementation_name": "cpython", "implementation_name": "cpython",
@ -60,6 +60,13 @@
], ],
"version": "==0.0.7" "version": "==0.0.7"
}, },
"django-meta": {
"hashes": [
"sha256:2a5b8d95099f69fb9736630c4fbf4fcc2972a1fcd9c708a5bb72dde22e84d8dd",
"sha256:4a7dc51c40fd6a097825040af29ee0e049f1fce29b006e39f266f80ba988bac6"
],
"version": "==1.4"
},
"gunicorn": { "gunicorn": {
"hashes": [ "hashes": [
"sha256:75af03c99389535f218cc596c7de74df4763803f7b63eb09d77e92b3956b36c6", "sha256:75af03c99389535f218cc596c7de74df4763803f7b63eb09d77e92b3956b36c6",

View file

@ -4,4 +4,7 @@ from users.models import User
def index(request): def index(request):
user = get_object_or_404(User, pk=1) user = get_object_or_404(User, pk=1)
return render(request, 'home/index.html', {'user': user}) return render(request, 'home/index.html', {
'user': user,
'meta': user.as_meta(request),
})

View file

@ -66,6 +66,7 @@ INSTALLED_APPS = [
'compressor', 'compressor',
'favicon', 'favicon',
'meta',
'lemoncurry', 'lemoncurry',
'home', 'home',
@ -182,3 +183,10 @@ MEDIA_ROOT = os.path.join(STATIC_ROOT, 'media')
# Settings specific to lemoncurry # Settings specific to lemoncurry
LEMONCURRY_SITE_NAME = '00dani.me' LEMONCURRY_SITE_NAME = '00dani.me'
# django-meta
# https://django-meta.readthedocs.io/en/latest/settings.html
META_SITE_PROTOCOL = 'https'
META_SITE_NAME = LEMONCURRY_SITE_NAME
META_USE_OG_PROPERTIES = True
META_USE_TWITTER_PROPERTIES = True

View file

@ -3,3 +3,5 @@ from .base import *
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']
STATIC_URL = 'https://static.00dani.dev/' STATIC_URL = 'https://static.00dani.dev/'
MEDIA_URL = STATIC_URL + 'media/' MEDIA_URL = STATIC_URL + 'media/'
META_SITE_DOMAIN = '00dani.dev'
META_FB_APPID = '142105433189339'

View file

@ -16,3 +16,5 @@ DATABASES['default'] = {
STATIC_URL = 'https://cdn.00dani.me/' STATIC_URL = 'https://cdn.00dani.me/'
MEDIA_URL = STATIC_URL + 'media/' MEDIA_URL = STATIC_URL + 'media/'
META_SITE_DOMAIN = '00dani.me'
META_FB_APPID = '145311792869199'

View file

@ -1,9 +1,10 @@
{% load compress favtags lemoncurry_tags static %}<!doctype html> {% load compress favtags lemoncurry_tags meta static %}<!doctype html>
<html lang="en" class="{% block html_class %}{% endblock %}"> <html lang="en" class="{% block html_class %}{% endblock %}">
<head> <head{% meta_namespaces %}>
<title class="p-name">{% site_name %}</title> <title class="p-name">{% site_name %}</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
{% include 'meta/meta.html' %}
{% placeFavicon %} {% placeFavicon %}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css"

View file

@ -1,5 +1,6 @@
from django.db import models from django.db import models
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
from meta.models import ModelMeta
def avatar_path(instance, name): def avatar_path(instance, name):
@ -18,10 +19,20 @@ class Site(models.Model):
ordering = ('name',) ordering = ('name',)
class User(AbstractUser): class User(ModelMeta, AbstractUser):
avatar = models.ImageField(upload_to=avatar_path) avatar = models.ImageField(upload_to=avatar_path)
note = models.TextField(blank=True) note = models.TextField(blank=True)
@property
def avatar_url(self):
return self.avatar.url
_metadata = {
'image': 'avatar_url',
'description': 'note',
'og_type': 'profile',
}
class Profile(models.Model): class Profile(models.Model):
user = models.ForeignKey( user = models.ForeignKey(