modified: .gitignore

new file:   content/2011-12-19-linkpeek-com-webpage-to-image-was-a-by-product.rst
	modified:   pelicanconf.py
	new file:   plugins/__init__.py
	renamed:    liblinkpeek.py -> plugins/liblinkpeek.py
	new file:   plugins/rst_linkpeek.py
This commit is contained in:
russellballestrini 2016-05-23 17:55:22 -04:00
parent b40cd54238
commit 08b54c3c53
6 changed files with 160 additions and 11 deletions

3
.gitignore vendored
View file

@ -5,6 +5,9 @@ __pycache__/
# C extensions
*.so
*.swp
# Distribution / packaging
.Python
env/

View file

@ -0,0 +1,53 @@
LinkPeek.com, webpage to image, was a by-product
################################################
:date: 2011-12-19 00:23
:author: Russell Ballestrini
:tags: LinkPeek, Opinion
:slug: linkpeek-com-webpage-to-image-was-a-by-product
:status: published
**tldr;** When faced with pivoting or killing a project, take a good
look at all possible by-products. Don't miss the hidden gem in a
project's slag!
Last year I built yoursitemakesmebarf.com, a novelty web application
which allowed anonymous link submission. The software would
automatically take
`screenshots <http://russell.ballestrini.net/linkpeek-com-web-address-thumbnail-api-alpha-release/>`__
of submitted links and curate a blog. I enjoyed building the site and
the project served as my first Pyramid application.
The project's original intent was to jokingly poke fun at ugly design.
The idea never caught on. Instead the application angered website owners
and attracted undesirable people. Eventually, I decided to take it down
and come up with less combative idea.
After witnessing the Goog release of "instant previews", I knew there
was a market for a fast and reliable web screen shot service.
.. linkpeek::
uri = https://linkpeek.com
size = 500x240
action = link_image
title = web page screen shot service
style = float: left; border-radius: 15px; margin-right: 15px;
So I decided to bring instant previews to anyone who needed them. I
wanted to build a fast, flexible, and easy to use screenshot API. After
a few months I had a working prototype. I named the product LinkPeek
because it described what the service was, and the domain was available.
Next I built a website thumbnail generator to show off the software. The
generator application helped reinforce the simplicity of the underlying
LinkPeek API. It didn't require any downloading, installation, or
waiting.
About a week later on a whim I posted the generator to hacker news.
I gave an honest title:
[linkpeek-hover uri="http://linkpeek.com/website-thumbnail-generator" text="Convert Any Webpage to an Image"]
and within about about 30 minutes LinkPeek.com was placed on the front page in the number 1 spot.
**Remember, when faced with pivoting or killing a project, take a good
look at all possible by-products. Don't miss the hidden gem in a
project's slag!**

View file

@ -11,8 +11,8 @@ DEFAULTS = {
#'THEME' : 'pelican-themes/svbhack',
'THEME' : 'pelican-themes/pelican-svbhack',
'REMARKBOX' : True,
'LINKPEEK_API_KEY' : None,
'LINKPEEK_SECRET_KEY' : None,
'LINKPEEK_APIKEY' : None,
'LINKPEEK_SECRET' : None,
}
def get_environ_or_default(key):
@ -26,8 +26,8 @@ THEME = get_environ_or_default('THEME')
REMARKBOX = get_environ_or_default('REMARKBOX')
LINKPEEK_API_KEY = get_environ_or_default('LINKPEEK_API_KEY')
LINKPEEK_SECRET_KEY = get_environ_or_default('LINKPEEK_SECRET_KEY')
LINKPEEK_APIKEY = get_environ_or_default('LINKPEEK_APIKEY')
LINKPEEK_SECRET = get_environ_or_default('LINKPEEK_SECRET')
# Theme specific
USER_LOGO_URL = 'https://lh3.googleusercontent.com/-uAPZy7NmmP0/AAAAAAAAAAI/AAAAAAAAAnI/iG2P43gCL2U/s125-c/photo.jpg'
@ -84,11 +84,17 @@ CATEGORY_SAVE_AS = 'category/{slug}/index.html'
TAG_SAVE_AS = 'tags/{slug}/index.html'
AUTHOR_SAVE_AS = 'author/{slug}/index.html'
# needed to add liblinkpeek filter
import ago
# Setup filters and plugins.
# register filters.
#JINJA_FILTERS = {'linkpeek':linkpeek}
# register linkpeek docutils directive.
import sys
sys.path.append('.')
import liblinkpeek
linkpeek = lambda uri, size : liblinkpeek.api_v1(uri, LINKPEEK_API_KEY, LINKPEEK_SECRET_KEY, size)
JINJA_FILTERS = {'linkpeek':linkpeek, 'ago':ago.human}
# done adding liblinkpeek filter
sys.path.append('plugins')
import rst_linkpeek
linkpeek = rst_linkpeek.LinkPeek
linkpeek.apikey = LINKPEEK_APIKEY
linkpeek.secret = LINKPEEK_SECRET
linkpeek.register()

0
plugins/__init__.py Normal file
View file

87
plugins/rst_linkpeek.py Normal file
View file

@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-
"""
Use LinkPeek via reStructuredText
=================================
This plugin allows you to use LinkPeek images from within reST documents.
"""
from __future__ import unicode_literals
from docutils import nodes
from docutils.parsers.rst import (
directives,
Directive,
)
from collections import defaultdict
#from .liblinkpeek import api_v1
from liblinkpeek import api_v1
class LinkPeek(Directive):
required_arguments = 0
optional_arguments = 0
final_argument_whitespace = True
has_content = True
apikey = None
secret = None
params = defaultdict(str)
def api_call(self):
return api_v1(self.params['uri'], self.apikey, self.secret, self.params['size'])
def _get_params(self):
"""
turn [u'uri = linkpeek.com', u'size = 200x200']
into {u'uri': u'linkpeek.com', u'size': u'200x200'}
"""
params = defaultdict(str)
for c in self.content:
# split on = and then remove leading/trailing whitespace.
key, value = c.split('=')
key = key.strip()
value = value.strip()
params[key] = value
self.params = params
return params
@property
def action_registry(self):
"""return an registry (dictionary) or action methods."""
return {
'image' : self.html_image,
'link_image' : self.html_link_image,
}
def get_action(self, action_name):
"""get action method from action registry or use default."""
return self.action_registry.get(action_name, self.api_call)
def html_image(self):
"""return html image markup."""
html = '<img src="{}" title="{}" style="{}" class="{}" />'
return html.format(self.api_call(), self.params['title'], self.params['style'], self.params['class'])
def html_link_image(self):
"""return html link image markup."""
html = '<a href="{}" target="_blank">{}</a>'
return html.format(self.params['uri'], self.html_image())
def run(self):
"""this method is fired when rendering."""
self._get_params()
action = self.get_action(self.params['action'])
output = action()
return [nodes.raw('', output, format='html')]
@classmethod
def register(cls):
"""register this directive/class with docutils."""
# this allows us to modify apikey and secret attributes before registering.
directives.register_directive('linkpeek', cls)