Deutsche Zope User Group
Gast 2 Benutzer online
DZUG-News

ListMetaTags (Script(Python) fuer CMF/Plone)

dynamische (Dublin Core) Meta-Tags mit einem Python-Script

Das Python-Script "ListMetaTags" wird (sollte) ueber das Header-Template ("/portal_skins/plone_templates/header") ausgefuehrt und sollte im Idealfall einige Meta-Tags in die HTML-Ausgabe einfuegen.

Das "ListMetaTags" hat aber einige Nachteile:
- es fehlt im CMF v1.3.2 ("/CMF/CMFDefault/skins/generic/listMetaTags.py")
- die letzten CVS-Versionen (http://cvs.zope.org/Products/CMFDefault/skins/generic/listMetaTags.py) laufen nicht ohne einschneidende Modifikationen
- die CVS-Versionen generieren nur einige wenige Dublin Core Metadaten

Da viele Suchmaschinen/Web-Robots/Web-Crawler neben den "klassischen" Meta-Daten mittlerweile auch Dublin Core Metadaten unterstuetzen, habe ich mir eine "customized" Version gebastelt, die als "Script(Python)" unter "/portal_skins/custom/ListMetaTags" erstellt wird.


Im nachfolgenden Beispiel werden einige Elemente ("keywords", "DC.subject") mit zusaetzlichen Werten belegt, andere ("copyright", "DC.rights") -falls leer- mit Default-Werten gefuellt und einige wenige ("revisit-after") sind statisch.

P.S.:
Da ich Python-Anfaenger bin, bitte ich um Nachsicht, manches kann sicherlich noch optimiert werden (konstruktive Kritik erwuenscht).


--CODE-->

hdrlist = []

keywords = []
if len(context.Subject()) > 0:
for i in context.Subject():
keywords.append(i)
keywords.append(',')
keywords= keywords + ["Linux","Debian","DEB","Packages","Debian Packages","ISO","ISO-Image","extra-cd","debian extra-cd","Linux Desktop"]
hdrlist.append(('keywords', ', '.join( keywords)))
hdrlist.append(('DC.subject', ', '.join( keywords)))

try:
if context.Description() != '':
description = context.Description()
elif context.Beschreibung != '':
description = context.Beschreibung
else:
description = "You are running Debian and it runs great, but there is just one problem: the software is a little bit outdated compared to other distributions. We are trying to provide some of the newest Debian packages for Desktop-Systems."
except:
description = "You are running Debian and it runs great, but there is just one problem: the software is a little bit outdated compared to other distributions. We are trying to provide some of the newest Debian packages for Desktop-Systems."

hdrlist.append( ('description', description))
hdrlist.append( ('DC.description', description))

if context.Language() == '':
hdrlist.append(('language', 'en'))
hdrlist.append(('DC.language', 'en'))
else:
hdrlist.append(('language', context.Language()))
hdrlist.append(('DC.language', context.Language()))

title = context.portal_url.Title() + " - " + context.title
hdrlist.append(('title', title))
hdrlist.append(('DC.title', title))

if context.Creator() != '':
hdrlist.append(('author', context.Creator()))
hdrlist.append(('DC.creator', context.Creator()))
else:
hdrlist.append(('creator', 'Alexander Reiterer, Robert Hase'))
hdrlist.append(('DC.creator', 'Alexander Reiterer, Robert Hase'))

if len(context.Contributors()) > 0:
for i in context.Contributors():
hdrlist.append(('DC.contributor', i))
else:
hdrlist.append(('DC.contributor', 'DECP'))
hdrlist.append(('DC.contributor', 'Alexander Reiterer'))
hdrlist.append(('DC.contributor', 'Robert Hase'))

hdrlist.append(('abstract', 'DECP - Debian-Extra-CD-Project, CD ISO-Images / DEB-Files with newest Packages'))
hdrlist.append(('DC.abstract', 'DECP - Debian-Extra-CD-Project, CD ISO-Images / DEB-Files with newest Packages'))

if context.Publisher() != 'No publisher':
hdrlist.append(('publisher', context.Publisher()))
hdrlist.append(('DC.publisher', context.Publisher()))
else:
hdrlist.append(('publisher', 'Robert Hase'))
hdrlist.append(('DC.publisher', 'Robert Hase'))

if context.Rights() != '':
hdrlist.append(('copyright', context.Rights()))
hdrlist.append(('DC.rights', context.Rights()))
else:
hdrlist.append(('copyright', 'Robert Hase'))
hdrlist.append(('DC.rights', 'Robert Hase'))

hdrlist.append(('revisit-after', 'after 7 days'))
hdrlist.append(('page-topic', 'Debian Extra-CD ISO / DEB-Packages'))
hdrlist.append(('page-type', 'Software'))
hdrlist.append(('audience', 'all'))
hdrlist.append(('robots', 'index,follow'))

hdrlist.append(('generator', context.portal_url()))

created = context.CreationDate()
hdrlist.append(('DC.date.created', created))
hdrlist.append(('date', context.ModificationDate()))
hdrlist.append(('DC.date.modified', context.ModificationDate()))

# Filter out DWIMish artifacts on effective / expiration dates
effective = context.effective_date
eff_str = ( effective and effective.year() > 1000
and effective != created ) and effective.Date() or ''

expires = getattr( context, 'expiration_date', None )
exp_str = ( expires and expires.year() < 9000 ) and expires.Date() or ''

if exp_str or exp_str:
hdrlist.append( ( 'DC.date.valid_range'
, '%s - %s' % ( eff_str, exp_str ) ) )

hdrlist.append( ( 'DC.type', context.Type() ) )
hdrlist.append( ( 'DC.format', context.Format() ) )

# Strip empty values
return filter( lambda x: x[1], hdrlist )

<--CODE--

Geschrieben von RHase . Letzte �nderung 27.02.2004 12:09.