Skip to content

Commit 578f284

Browse files
committed
testando novo layout malt
1 parent d19dea7 commit 578f284

File tree

14 files changed

+600
-23
lines changed

14 files changed

+600
-23
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .better_figures_and_images import *
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"""
2+
Better Figures & Images
3+
------------------------
4+
5+
This plugin:
6+
7+
- Adds a style="width: ???px; height: auto;" to each image in the content
8+
- Also adds the width of the contained image to any parent div.figures.
9+
- If RESPONSIVE_IMAGES == True, also adds style="max-width: 100%;"
10+
- Corrects alt text: if alt == image filename, set alt = ''
11+
12+
TODO: Need to add a test.py for this plugin.
13+
14+
"""
15+
16+
from __future__ import unicode_literals
17+
from os import path, access, R_OK
18+
19+
from pelican import signals
20+
21+
from bs4 import BeautifulSoup
22+
from PIL import Image
23+
24+
import logging
25+
logger = logging.getLogger(__name__)
26+
27+
def content_object_init(instance):
28+
29+
if instance._content is not None:
30+
content = instance._content
31+
soup = BeautifulSoup(content, "lxml")
32+
33+
if 'img' in content:
34+
for img in soup('img'):
35+
logger.debug('Better Fig. PATH: %s', instance.settings['PATH'])
36+
logger.debug('Better Fig. img.src: %s', img['src'])
37+
38+
img_path, img_filename = path.split(img['src'])
39+
40+
logger.debug('Better Fig. img_path: %s', img_path)
41+
logger.debug('Better Fig. img_fname: %s', img_filename)
42+
43+
# Strip off {filename}, |filename| or /static
44+
if img_path.startswith(('{filename}', '|filename|')):
45+
img_path = img_path[10:]
46+
elif img_path.startswith('/static'):
47+
img_path = img_path[7:]
48+
else:
49+
logger.warning('Better Fig. Error: img_path should start with either {filename}, |filename| or /static')
50+
51+
# Build the source image filename
52+
src = instance.settings['PATH'] + img_path + '/' + img_filename
53+
54+
logger.debug('Better Fig. src: %s', src)
55+
if not (path.isfile(src) and access(src, R_OK)):
56+
logger.error('Better Fig. Error: image not found: %s', src)
57+
58+
# Open the source image and query dimensions; build style string
59+
im = Image.open(src)
60+
extra_style = 'width: {}px; height: auto;'.format(im.size[0])
61+
62+
if 'RESPONSIVE_IMAGES' in instance.settings and instance.settings['RESPONSIVE_IMAGES']:
63+
extra_style += ' max-width: 100%;'
64+
65+
if img.get('style'):
66+
img['style'] += extra_style
67+
else:
68+
img['style'] = extra_style
69+
70+
if img['alt'] == img['src']:
71+
img['alt'] = ''
72+
73+
fig = img.find_parent('div', 'figure')
74+
if fig:
75+
if fig.get('style'):
76+
fig['style'] += extra_style
77+
else:
78+
fig['style'] = extra_style
79+
80+
instance._content = soup.decode()
81+
82+
83+
def register():
84+
signals.content_object_init.connect(content_object_init)

.plugins/sitemap/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .sitemap import *

.plugins/sitemap/sitemap.py

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
# -*- coding: utf-8 -*-
2+
'''
3+
Sitemap
4+
-------
5+
6+
The sitemap plugin generates plain-text or XML sitemaps.
7+
'''
8+
9+
from __future__ import unicode_literals
10+
11+
import collections
12+
import os.path
13+
14+
from datetime import datetime
15+
from logging import warning, info
16+
from codecs import open
17+
from pytz import timezone
18+
19+
from pelican import signals, contents
20+
from pelican.utils import get_date
21+
22+
TXT_HEADER = """{0}/index.html
23+
{0}/archives.html
24+
{0}/tags.html
25+
{0}/categories.html
26+
"""
27+
28+
XML_HEADER = """<?xml version="1.0" encoding="utf-8"?>
29+
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
30+
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
31+
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
32+
"""
33+
34+
XML_URL = """
35+
<url>
36+
<loc>{0}/{1}</loc>
37+
<lastmod>{2}</lastmod>
38+
<changefreq>{3}</changefreq>
39+
<priority>{4}</priority>
40+
</url>
41+
"""
42+
43+
XML_FOOTER = """
44+
</urlset>
45+
"""
46+
47+
48+
def format_date(date):
49+
if date.tzinfo:
50+
tz = date.strftime('%z')
51+
tz = tz[:-2] + ':' + tz[-2:]
52+
else:
53+
tz = "-00:00"
54+
return date.strftime("%Y-%m-%dT%H:%M:%S") + tz
55+
56+
class SitemapGenerator(object):
57+
58+
def __init__(self, context, settings, path, theme, output_path, *null):
59+
60+
self.output_path = output_path
61+
self.context = context
62+
self.now = datetime.now()
63+
self.siteurl = settings.get('SITEURL')
64+
65+
66+
self.default_timezone = settings.get('TIMEZONE', 'UTC')
67+
self.timezone = getattr(self, 'timezone', self.default_timezone)
68+
self.timezone = timezone(self.timezone)
69+
70+
self.format = 'xml'
71+
72+
self.changefreqs = {
73+
'articles': 'monthly',
74+
'indexes': 'daily',
75+
'pages': 'monthly'
76+
}
77+
78+
self.priorities = {
79+
'articles': 0.5,
80+
'indexes': 0.5,
81+
'pages': 0.5
82+
}
83+
84+
config = settings.get('SITEMAP', {})
85+
86+
if not isinstance(config, dict):
87+
warning("sitemap plugin: the SITEMAP setting must be a dict")
88+
else:
89+
fmt = config.get('format')
90+
pris = config.get('priorities')
91+
chfreqs = config.get('changefreqs')
92+
93+
if fmt not in ('xml', 'txt'):
94+
warning("sitemap plugin: SITEMAP['format'] must be `txt' or `xml'")
95+
warning("sitemap plugin: Setting SITEMAP['format'] on `xml'")
96+
elif fmt == 'txt':
97+
self.format = fmt
98+
return
99+
100+
valid_keys = ('articles', 'indexes', 'pages')
101+
valid_chfreqs = ('always', 'hourly', 'daily', 'weekly', 'monthly',
102+
'yearly', 'never')
103+
104+
if isinstance(pris, dict):
105+
# We use items for Py3k compat. .iteritems() otherwise
106+
for k, v in pris.items():
107+
if k in valid_keys and not isinstance(v, (int, float)):
108+
default = self.priorities[k]
109+
warning("sitemap plugin: priorities must be numbers")
110+
warning("sitemap plugin: setting SITEMAP['priorities']"
111+
"['{0}'] on {1}".format(k, default))
112+
pris[k] = default
113+
self.priorities.update(pris)
114+
elif pris is not None:
115+
warning("sitemap plugin: SITEMAP['priorities'] must be a dict")
116+
warning("sitemap plugin: using the default values")
117+
118+
if isinstance(chfreqs, dict):
119+
# .items() for py3k compat.
120+
for k, v in chfreqs.items():
121+
if k in valid_keys and v not in valid_chfreqs:
122+
default = self.changefreqs[k]
123+
warning("sitemap plugin: invalid changefreq `{0}'".format(v))
124+
warning("sitemap plugin: setting SITEMAP['changefreqs']"
125+
"['{0}'] on '{1}'".format(k, default))
126+
chfreqs[k] = default
127+
self.changefreqs.update(chfreqs)
128+
elif chfreqs is not None:
129+
warning("sitemap plugin: SITEMAP['changefreqs'] must be a dict")
130+
warning("sitemap plugin: using the default values")
131+
132+
def write_url(self, page, fd):
133+
134+
if getattr(page, 'status', 'published') != 'published':
135+
return
136+
137+
# We can disable categories/authors/etc by using False instead of ''
138+
if not page.save_as:
139+
return
140+
141+
page_path = os.path.join(self.output_path, page.save_as)
142+
if not os.path.exists(page_path):
143+
return
144+
145+
lastdate = getattr(page, 'date', self.now)
146+
try:
147+
lastdate = self.get_date_modified(page, lastdate)
148+
except ValueError:
149+
warning("sitemap plugin: " + page.save_as + " has invalid modification date,")
150+
warning("sitemap plugin: using date value as lastmod.")
151+
lastmod = format_date(lastdate)
152+
153+
if isinstance(page, contents.Article):
154+
pri = self.priorities['articles']
155+
chfreq = self.changefreqs['articles']
156+
elif isinstance(page, contents.Page):
157+
pri = self.priorities['pages']
158+
chfreq = self.changefreqs['pages']
159+
else:
160+
pri = self.priorities['indexes']
161+
chfreq = self.changefreqs['indexes']
162+
163+
pageurl = '' if page.url == 'index.html' else page.url
164+
165+
#Exclude URLs from the sitemap:
166+
sitemapExclude = []
167+
168+
if self.format == 'xml':
169+
if pageurl not in sitemapExclude:
170+
fd.write(XML_URL.format(self.siteurl, pageurl, lastmod, chfreq, pri))
171+
else:
172+
fd.write(self.siteurl + '/' + pageurl + '\n')
173+
174+
def get_date_modified(self, page, default):
175+
if hasattr(page, 'modified'):
176+
if isinstance(page.modified, datetime):
177+
return page.modified
178+
return get_date(page.modified)
179+
else:
180+
return default
181+
182+
def set_url_wrappers_modification_date(self, wrappers):
183+
for (wrapper, articles) in wrappers:
184+
lastmod = datetime.min.replace(tzinfo=self.timezone)
185+
for article in articles:
186+
lastmod = max(lastmod, article.date.replace(tzinfo=self.timezone))
187+
try:
188+
modified = self.get_date_modified(article, datetime.min).replace(tzinfo=self.timezone)
189+
lastmod = max(lastmod, modified)
190+
except ValueError:
191+
# Supressed: user will be notified.
192+
pass
193+
setattr(wrapper, 'modified', str(lastmod))
194+
195+
def generate_output(self, writer):
196+
path = os.path.join(self.output_path, 'sitemap.{0}'.format(self.format))
197+
198+
pages = self.context['pages'] + self.context['articles'] \
199+
+ [ c for (c, a) in self.context['categories']] \
200+
+ [ t for (t, a) in self.context['tags']] \
201+
+ [ a for (a, b) in self.context['authors']]
202+
203+
self.set_url_wrappers_modification_date(self.context['categories'])
204+
self.set_url_wrappers_modification_date(self.context['tags'])
205+
self.set_url_wrappers_modification_date(self.context['authors'])
206+
207+
for article in self.context['articles']:
208+
pages += article.translations
209+
210+
info('writing {0}'.format(path))
211+
212+
with open(path, 'w', encoding='utf-8') as fd:
213+
214+
if self.format == 'xml':
215+
fd.write(XML_HEADER)
216+
else:
217+
fd.write(TXT_HEADER.format(self.siteurl))
218+
219+
FakePage = collections.namedtuple('FakePage',
220+
['status',
221+
'date',
222+
'url',
223+
'save_as'])
224+
225+
for standard_page_url in ['index.html',
226+
'archives.html',
227+
'tags.html',
228+
'categories.html']:
229+
fake = FakePage(status='published',
230+
date=self.now,
231+
url=standard_page_url,
232+
save_as=standard_page_url)
233+
self.write_url(fake, fd)
234+
235+
for page in pages:
236+
self.write_url(page, fd)
237+
238+
if self.format == 'xml':
239+
fd.write(XML_FOOTER)
240+
241+
242+
def get_generators(generators):
243+
return SitemapGenerator
244+
245+
246+
def register():
247+
signals.get_generators.connect(get_generators)

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ before_install:
2121
install:
2222
- pip install --upgrade pip
2323
- pip install -r requirements.txt
24+
- git clone https://github.com/grupydf/malt
25+
- pelican-themes -i malt
2426
script:
2527
- make github
File renamed without changes.

content/hello-python-mg.rst

Lines changed: 0 additions & 9 deletions
This file was deleted.
2.29 MB
Loading

content/images/logo/logo.png

12.6 KB
Loading

content/pages/comunidade.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Comunidade
2+
##########
3+
:slug: comunidade
4+
:template: comunidade

0 commit comments

Comments
 (0)