Moved comment section code to a separate file, making replacement/removement easier

master
Stefan Krulj 14 years ago
parent 62f02eea6d
commit 57875365cd
  1. 40
      comment_section.py
  2. 27
      pylog.py
  3. 36
      pylog_config.py

@ -0,0 +1,40 @@
import urllib, os
import pylog_config as cfg
__commentanchor="#disqus_thread" #The anchor name of the comment section
def comments_init():
print """<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'pylog'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function () {
var s = document.createElement('script'); s.async = true;
s.type = 'text/javascript';
s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>"""
def disp_comments(file):
"""<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'pylog'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>"""
def disp_num_of_comments(file):
sys.stdout.write('<a class="commentcount" href="'+cfg.topurl+script+'?')
sys.stdout.write(urllib.urlencode({'path': os.path.normpath(os.path.dirname(file)), \
'disp':os.path.normpath(file)}).replace('&','&amp;')+__commentanchor+'"></a>')

@ -11,6 +11,7 @@ from datetime import datetime
from pylog_action import *
import pylog_config as cfg
import comment_section
__version = "v0.1-(2012-03-15)"
@ -71,6 +72,10 @@ def disp_list(path):
files = {}
for f in os.listdir(path):
f = os.path.normpath(os.path.join(path,f))
if get_valid_path(f)==cfg.contentdir:
continue
if not os.path.isdir(f):
if not os.path.getmtime(f) in files:
files[os.path.getmtime(f)]=[f]
@ -99,9 +104,9 @@ def disp_file_dict(d,keys):
print name+'</a> - <span class="entrydate">',
print datetime.fromtimestamp(int(k)).strftime(cfg.datefmt),
print '</span>&nbsp;'
sys.stdout.write('<a class="commentcount" href="'+cfg.topurl+script+'?')
sys.stdout.write(urllib.urlencode({'path': os.path.normpath(os.path.dirname(f)), \
'disp':os.path.normpath(f)}).replace('&','&amp;')+cfg.commentanchor+'"></a>')
comment_section.disp_num_of_comments(f)
print '</h1>'
prev_actions[typ](f)
@ -150,7 +155,7 @@ def get_newest(n):
def get_valid_path(path):
if '..' in path or os.path.normpath(path)=='.':
return cfg.contentdir
valid_chars='. abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/_0123456789'
valid_chars='. abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/_-0123456789'
for c in path:
if not c in valid_chars:
return cfg.contentdir
@ -228,6 +233,7 @@ print '<meta charset="UTF-8">'
print ('<title>'+cfg.title+'</title>').encode(cfg.encoding)
print '<link rel="alternate" type="application/rss+xml" title="RSS" href="'+cfg.topurl+script+'"?rss=1 />'
print cfg.header.encode(cfg.encoding)
comment_section.comments_init()
print '</head>'
print '<body>'
print ('<h1 id="blogtitle"><a href="'+script+'">'+cfg.blogtitle+'</a></h1>').encode(cfg.encoding)
@ -257,7 +263,13 @@ try:
).strftime(cfg.datefmt),
print '</span></h1>'
disp_actions[typ](validdisp)
comment_section.disp_actions[typ](validdisp)
print '<hr>'
print '<div id="footer">'
print cfg.footer
disp_comments(validdisp)
print '</div>'
else:
disp_list(path)
except OSError as ose:
@ -266,11 +278,6 @@ except OSError as ose:
print '<span style="color:#f00>-- [!]&nbsp;Error&nbsp;[!] --<br>'
print ose.strerror + '</span>'
if 'disp' in form:
print '<hr>'
print '<div id="footer">'
print cfg.footer
print '</div>'
print '</body>'
print '</html>'

@ -2,42 +2,14 @@ title = 'PyLog' # Title displayed on the browser window/tab
blogtitle= 'Plog' # The blog's title
subtitle=u'produced py Powertomato \xb0\u0DF4\xb0' # The text to be displayed under the blog title
# This header will be printed in the <head> section of the html file
header="""
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="source.css" />
"""
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'pylog'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function () {
var s = document.createElement('script'); s.async = true;
s.type = 'text/javascript';
s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>
""" # This header will be printed in the <head> section of the html file
footer="""
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'pylog'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
""" # This footer will be printed at the end of the <body> tag
commentanchor="#disqus_thread" #The anchor name of the comment section
# This footer will be printed at the end of the <body> tag
footer=""
datefmt='%Y-%m-%d' # format of the date which is displayed next to the entry
# See pythons manual reference for time.strptime for details

Loading…
Cancel
Save