Blogger和WordPress的倒序显示
blogger和都可以通过一定的设置,变成一个只供自己查看的私人博客,相当于私人日记本,具体方法是,在博客设置里将其设置为只有作者才能查看,然后将博客设置为在一页内全部显示(比如设置单页文章1千篇),在博客安装一个倒序显示脚本,即可完成日记本的功能,可供导出和打印。
除了打印,还可以将内容复制到txt文件里,在邮箱里发送到kindle邮箱,然后在自己的kindle上看,相当于看书的体验。
这里面的一个技术问题是如何在blogger和wordpress里实现按照日期倒序显示(reverse post order)。这里分别给出blogger和wordpress实现倒序的方法。
在blogger中,页脚点击“添加小工具”,添加“html/javascript”微件,之后在微件内容里插入如下代码:
<!-- start post reversal code -->
<script type='text/javascript'>
//<![cdata[
// -----------------------------------------------------------------------------------------
// name : prs - post reversal script for blogger - version 1.0
// author : david yockey
// url : techsquirrels.blogspot.com/2012/04/swapping-to-reverse-post-order-on.html
// -----------------------------------------------------------------------------------------
// temp variable used to shorten classname references
var cn;
// this function is called as needed in the main program below.
function reverseposts(blogpostcontainer,postclass) {
// arguments:
// blogpostcontainer -- the node containing the posts to be reversed.
// postclass -- the classname of each of the posts in the container to be reversed.
// (may be a single name from among names in the class attribute of the posts)
// flag for checking whether any posts are found
var found=false;
var blogposts = blogpostcontainer.childnodes; // may include text-nodes containing
// whitespace in addition to post-nodes
// set index variables to top and bottom of blogposts list
var i=0;
var j=blogposts.length-1;
for( ; ; ) { // start endless loop
// find next post from the top
while( (i < j) && (!(cn=blogposts[i].classname) || !(cn.match(postclass))) )
++i;
// find next post from the bottom
while( (i < j) && (!(cn=blogposts[j].classname) || !(found=cn.match(postclass))) ) // (see footnote 1)
--j;
if( found && i < j ) {
// swap posts (see footnote 2)
var tempi = blogposts[i].clonenode(true); // store a copy of post i in tempi
var tempj = blogposts[j].clonenode(true); // store a copy of post j in tempj
blogpostcontainer.replacechild(tempi,blogposts[j]); // replace post j with post i in tempi
blogpostcontainer.replacechild(tempj,blogposts[i]); // replace post i with post j in tempj
} else {
// done
break; // break out of endless loop
}
++i; --j;
}
}
// footnote 1:
// if a post is found from one end, then a post must necessarily be found from the other.
// so, recording and later checking for a post from one end is sufficient to ensure that
// one was found from both.
//
// footnote 2:
// at least in 11.0 on fedora linux, replacing a child directly with another child
// causes some text-nodes containing whitespace to be deleted. that node deletion messes up
// the positions of the posts in the blogposts list. this is avoided by cloning both posts
// rather than just one and replacing both posts from the cloned copies.
// *** main post reversal program ***
// magic words
var blogwidget = 'blog1';
var blogpostcontainerclass = 'blog-posts';
var blogpostclass = 'date-outer';
var datepostcontainerclass = 'date-posts';
var datepostclass = 'post-outer';
var blog1 = document.getelementbyid(blogwidget);
// find the node containing the blog posts
var blogpostcontainer;
var x=0;
do {
blogpostcontainer = blog1.childnodes[x++];
} while ( !(cn=blogpostcontainer.classname) || !(cn.match(blogpostcontainerclass)) );
// reverse different day posts
reverseposts(blogpostcontainer,blogpostclass);
// reverse same day posts - loop thru contents of blogpostcontainer to find each day's posts
var blogposts = blogpostcontainer.childnodes;
for ( i = 0; i < blogposts.length; ++i ) {
// check for an actual post-node rather than a text-node or such
if ( (cn=blogposts[i].classname) && cn.match(blogpostclass) ) {
var datepostcontainer;
x=0;
// find the node containing the posts to be reversed for the current day being processed
do {
datepostcontainer = blogposts[i].childnodes[x++];
} while ( !(cn=datepostcontainer.classname) || !(cn.match(datepostcontainerclass)) );
reverseposts(datepostcontainer,datepostclass);
}
}
//]]>
</script>
<!-- end post reversal code -->
之后保存,设置“主页上显示的博文数量上限”的数量,然后打开页面即可看到倒序的文章。
对于来说,操作起来比较简单,安装一个名为“chronological posts”的plugin即可实现倒序文章。
从安全性来说,blogger更为安全一些,谷歌帐号设置两步验证,在谷歌blogger中写内容,然后设置只有自己只读,安装一个倒序显示脚本,然后复制到txt文件里,在邮箱里发送到kindle邮箱,然后在自己的kindle上看,看完了就删,只要谷歌帐号不泄露,秘密的信息就不会泄漏。
推荐阅读
-
对Python中list的倒序索引和切片实例讲解
-
Blogger和WordPress的倒序显示
-
在centos7下面安装了lnmp和wordpress,现在wordpress目录在网络的二级目录下,想显示为一级目录
-
对Python中list的倒序索引和切片实例讲解
-
在centos7下面安装了lnmp和wordpress,现在wordpress目录在网络的二级目录下,想显示为一级目录
-
显示带有分类法和自定义帖子类型的WordPress相关帖子
-
WordPress中鼠标悬停显示和隐藏评论及引用按钮的实现_javascript技巧
-
Lua实现正序和倒序的文件读取方法
-
kendo UI 倒如css 和 js 后 窗口控件上的工具栏图标不显示如何解决
-
判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。