Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions custom-plugins/random_articles/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Random Articles Plugin For Pelican
========================

This plugin insert a variable called `random_articles` in the page context.
Only published articles are listed.


Settings options:

RANDOM_ARTICLES = 3 # show only 3 random articles
SKIP_ARTICLES = 10 # skip 10 first articles before randomize


Usage
-----

To change number of random articles, put on your settings:

RANDOM_ARTICLES = 3

Then in some template you'll have a variable called `random_articles`.

Ex:
{% for article in random_articles %}
<p class="article-link tagline">
<a href="{{ SITEURL }}/{{ article.url}}">{{ article.title }}</a>
</p>
{% endfor %}
1 change: 1 addition & 0 deletions custom-plugins/random_articles/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .random_articles import *
37 changes: 37 additions & 0 deletions custom-plugins/random_articles/random_articles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

import random

from pelican import signals


def is_published(article):
""" Return if article is published"""
return getattr(article, 'status', 'published') == 'published'


def get_articles(generator):
skip_articles = generator.settings.get('SKIP_ARTICLES', 0)
articles = generator.context['articles']
return articles[skip_articles:]


def register_articles(generator, metadata):
articles = filter(is_published, get_articles(generator))
articles_number = len(articles)

random_articles_number = generator.settings.get('RANDOM_ARTICLES', 3)

# we should return only articles number that exists
sample_number = random_articles_number
if articles_number < random_articles_number:
sample_number = articles_number

random_articles = random.sample(articles, sample_number)
generator.context['random_articles'] = random_articles


def register():
signals.page_generator_context.connect(register_articles)
15 changes: 11 additions & 4 deletions pelicanconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals
import os


BASE = os.path.dirname(__file__)

AUTHOR = u'PythonClub'
Expand Down Expand Up @@ -54,19 +56,24 @@

# Plugins
PLUGIN_PATHS = [
'pelican-plugins'
'pelican-plugins',
'custom-plugins'
]

PLUGINS = [
'gravatar',
'sitemap',
'pelican_youtube', # funciona somente com arquivos rst
'pelican_vimeo', # funciona somente com arquivos rst
'gzip_cache', # deve ser o ultimo plugin
'pelican_youtube', # funciona somente com arquivos rst
'pelican_vimeo', # funciona somente com arquivos rst
'random_articles',
'gzip_cache' # deve ser o ultimo plugin
# 'pdf', # funciona somente com arquivos rst

]

RANDOM_ARTICLES = 10
SKIP_ARTICLES = 10


SITEMAP = {
'format': 'xml',
Expand Down
16 changes: 16 additions & 0 deletions theme/static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ code {
width: 80%;
}

.articles-random {
font-size: 0.8em;
}

.article-link {
margin-top: 0px;
line-height: 1em;
}


@media (max-width: 767px) {
.brand-main a img {
display: inline;
Expand All @@ -99,6 +109,12 @@ code {
.google-search {
width: 100%;
}

.articles-random, .articles-link {
display: none;
}


}

@media (max-width: 480px) {
Expand Down
20 changes: 11 additions & 9 deletions theme/templates/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@ <h1 class="brand-main"><a href="/"><img src="{{ SITELOGO }}" alt="{{ SITENAME }}
{% for title, link in MENUITEMS %}
<p class="links"><a href="{{ SITEURL }}/{{ link }}">{{ title }}</a></p>
{% endfor %}

<div class="section articles-random">
<h1 class="tagline">Não deixe de ver!</h1>

{% for article in random_articles %}
<p class="article-link tagline">
<a href="{{ SITEURL }}/{{ article.url}}">{{ article.title }}</a>
</p>
{% endfor %}
</div>

<p class="social">
{% for title, link in SOCIAL %}
<a href="{{ link }}">
<i class="fa fa-{{ title }} fa-3x"></i>
</a>
{% endfor %}
</p>
<div class="section">
<span><a href="http://2014.pythonbrasil.org.br/">#Python2014, vamos?!</a></span>
<div class="section-body">
<a href="http://2014.pythonbrasil.org.br/" >
<img src="https://pybr.s3.amazonaws.com/static/images/badges/badge-pt-br.2ab99f7699bf.png"
width="250" height="276" alt="Eu vou na PythonBrasil[10]"/>
</a>
</div>
</div>
<p class="tagline">
Esta comunidade é signatária do
<a target="_blank" href="http://smallactsmanifesto.org" title="Small Acts Manifesto">
Expand Down