搜索此博客

2007年3月30日星期五

又从 Typo 搬到 Mephisto 了……

Hack 1: 文章 meta 的修改



这里的 meta 是指每个 entry 下面一小块区域,包括文章作者、所属分类等信息,以及指向评论的链接。最初的模板没有订阅评论的链接,也没有文章所属 tag 的信息,所以改动模板的 _shared.liquid 文件如下,加入:






1
2

<span class="tag">Tagged {{ article | linked_tag_list }}</span>



以及:






1
2
3
4
5

6
7
8

{% unless mode == 'single' %}
{% if article.accept_comments %}
<a href="{{ article.url }}#comments" class="commentslink">

{{ article.comments_count | pluralize: 'comments' }} &#187;</a> &nbsp;
<a href="{{ article.comments_feed_url }}" class="commentslink">

Subscribe to comments</a>{% endif %}
{% endunless %}


代码基本是自解释的,我就不说啥了。



Hack 2: 每次都要折腾的分类 feed 链接



分类的链接比较简单,Mephisto 的 wiki 上有说明,另有一个 articles_feed 的 filter 可以帮助获取用于自动识别的 feed,加上后会在 html 的 <head&rt; 部分加入 feed 地址,像 Firefox 这样的浏览器就可以自动发现这些 feed。但为了让使用 IE 之类浏览器的人也能看到 feed,就比较麻烦,google 了半天之后发现 mephisto 提供了一个 helper,叫 section_feed_url,终于搞定,代码是这个样子:






1
2
3

4
5
6
7
8
9
10


<ul>
{% for category in site.blog_sections %}
{% unless category.name == 'Home' %}
<li>{{ category | link_to_section }} ({{ category.articles_count }})
{{ category | articles_feed }}
<a href="{{ category | section_feed_url }}" class="tiny">(atom)</a>

</li>
{% endunless %}{% endfor %}
</ul>


折腾了一通之后发现有人写了插件提供这个功能……另外 Home 分类是默认的,就是全部文章,这里用 unless 把它去掉。



Hack 3: 最近评论



这是 0.7.3 最新支持的功能,在 CHANGELOG 里他们给出了一种用法,但无论怎么改参数,给出的评论数总是跟默认的页面文章数一致,似乎是参数没有传递过去。后来还是在 Mephisto Wiki 上的提问与回答部分找到了一段代码,依葫芦画瓢:






1
2
3

4
5
6
7
8

{{ site | latest_comments:5 | assign_to:"comments" }}

<ul>
{% for comment in comments %}
<li>{{ comment.author_link }} on {{ comment | link_to_article }} -
{{ comment.body | truncatewords: 10 }}</li>
{% endfor %}

</ul>


至今也不明白为什么像 {{ site | latest_comments :5 }} 这样的代码不行,非得用 assign_to。



Hack 4: 每月文章



这个也是 Mephisto Wiki 上直接给了解决办法的,直接贴出代码:






1
2
3
4
5

6
7
8
9
10

<ul>
{% for month in site.home_section.months %}

{{ site.home_section | monthly_articles: month | size | assign_to: 'articles_count' }}
{% if articles_count > 0 %}
<li>{{ site.home_section | link_to_month: month }}
({{ articles_count }})</li>
{% endif %}

{% endfor %}
</ul>


Hack 5: 分类存档



我最得意的 hack :)。Mephisto 的作者非常痛恨 blog 分页,据说是因为这样文章的链接会随其页面位置改变,不方便别人用搜索引擎查找,所以 Mephisto 默认没有分页功能,也没有“上一页”这样的选项。还好每月的文章是可以全部显示的,但查看分类、搜索和首页的文章数等等都要受同一个变量的控制。首页没有早期文章的链接还可以忍,分类也只能看十几篇就比较过分了,好在摸索之后发现每个分类也是可以按照月份显示所有文章的,通过以下代码:






1

2
3
4
5
6
7
8
9
10


<ul>
{% for month in section.months %}
{{ section | monthly_articles: month | size | assign_to: 'articles_count' }}
{% if articles_count > 0 %}

<li class="month">{{ section | link_to_month: month }}
({{ articles_count }}) </li>
{% endif %}
{% endfor %}

</ul>


建立一个分类页面专用的模板,在 sidebar 部分加入即可通过每月文章访问到分类中所有的文章。但是这样跟我所要的效果还有一些差距。怎样能看到所有文章的标题呢?参考上面的代码,我依葫芦画瓢写了如下的代码,试验了一下,运气不错:






1
2
3

4
5
6
7
8
9
10
11
12

13
14
15

<ul>
{% for month in section.months %}
{{ section | monthly_articles: month | size | assign_to: 'articles_count' }}

{% if articles_count > 0 %}
<li class="month">{{ section | link_to_month: month }}
({{ articles_count }})
{{ section | monthly_articles: month | assign_to: 'articlesmonth' }}

{% for article in articlesmonth %}
<li>{{ article | link_to_article }}</li>
{% endfor %}
</li>
{% endif %}

{% endfor %}
</ul>


增加了一重循环,在每月文章内再分别列出文章的题目,第二个 assign_to 的用法比较有趣。



Hack 6: Gravatar 支持



Mephisto 的管理界面直接支持 Gravatar 的头像,但我一开始没有找到对应的 filter,而插件工作也始终不正常。困扰了许久后在 Google Groups 上的 Mephisto Blog 小组找到了答案,原来 filter 就在 mephisto/apps/helper/url_filters.rb 这个文件中:






1
2
3
4
5

6
7
8
9
10
11
12


####################################################
def gravatar_author(author, size=80, default=nil)
return '' unless author['email']

url = "http://www.gravatar.com/avatar.php?
size=
#{size}&gravatar_id=#{Digest::MD5.hexdigest(author['email'])}"


url << "&default=#{default}" if default

image_tag url, :class => 'gravatar', :size =>

"#{size}x#{size}", :alt => "author['login']"
end

####################################################


修改一下评论模板,在合适的地方加上 {{ comment | gravatar: 32, "http://snakehsu.info/contacts.png"}},即可看到评论者的 gravatar。两个参数分别是头像的大小和没有头像时的默认图像。



顺便说一句,前几天 gravatar 工作不正常是因为数据库和服务器的配合问题,目前已经基本解决,但是需要用户自己登录 gravatar 再重新提交一次头像。



Hack 7 & 8: 搜索和 Tag Cloud



如上面所说,内置搜索的结果只能给出最初十几个,所以我试图用 Google 定制搜索引擎 来解决这个问题,不过看来 Google 还没有来得及索引这个新地址,所以这几天内估计用 Google 搜不到这里的东西,且看看过一周后怎么样。



Tag Cloud 也是用的现成的插件,唯一的问题是域名不一致,因为它认为我的 blog 的基础地址是 snakehsu.info 而不是 snakehsu.info/main/,我也没空钻研 URL 重写的问题,就直接改了插件的源文件了事,这个是我唯一的一处”硬“修改。



现在这个新 blog 基本实现了过去 Wordpress blog 的所有功能,有些地方还更方便,比如内置的 Gravatar 支持和 Markdown (类似 emacs-wiki 的标记语言)。折腾了好久,现在基本可以熟练地在共享主机上安装 Ruby on Rails 程序了……

2007年3月29日星期四

Word: "panmictic"

It means of panmicxia: random mating within a breeding population.

According to [Merriam-Webster](http://www.webster.com/dictionary/panmixia).

2007年3月28日星期三

从 Wordpress 搬到 Typo 了

而且总算把两个 blog 统一了。导入原来 [blog](http://snakehsu.info/blog) 的文章时发现刚好写了365篇 entry,不知道有没有什么寓意,呵呵。

2007年3月26日星期一

Methodology reconsidered

An adaptive cycle

I overlooked a fact that resilience is only one dimension of the adaptive cycle.  To really use an adaptive cycle to measure resilience I will need to know three values: the position of the system in the cycle, the connectedness of the system, and the system's potential, which is perhaps outside my thesis's scope.

Thus the resilience should be measured by other methods, focusing on slowly changing variables.  The outcome -- measurement of resilience, can be used in the future if I want to find out about the system's adaptive cycle.

To understand the history of the system and determine its position in the cycle will still be useful.  It will help with understanding of current status and relative resilience of the system.

2007年3月25日星期日

Week 25: Get my hands dirty

The feedback on my previous piece of writing on resilience is a bit unexpected.  Apparently my supervisors and I have some disagreement on our perception of resilience.  The resilience I am familiar with has a strong ecological origin and may not be quite the same as those about social-economic systems.  It is suggested that I take a look at vulnerability studies in both social and ecological terms. 

The introduce of the concept in my writing is a bit too steep.  Considering the audience of my thesis I am also told to rewrite the piece to make it more understandable by others.  More examples, if available, can make my writing more detailed and grounded.

The following three week or so, I will divert considerable time and effort to make a series of plans for the field trip.  It is not as interesting as studying concepts, but will be an essential part of my project.

2007年3月23日星期五

Drawing drokpas away from the pasture: Good or evil?

I just noticed that it is part of the state's pastoralism policy that drokpas are not only encouraged to reduce or stop grazing on certain pastures, but also to leave the land and enter the Third Industry.

The rationale behind this is that drokpas are mostly living a materially-deprived life.  The policy will help them get richer by drawing them into service industries.  The drokpas remain on the pasture will then be able to have larger pastures for their herds, and eventually become ranch managers like those in the U. S. or Australia. 

But such measure does not necessarily increase individual pastoralists' strength, or resilience, in the face of sudden natural disasters.  Traditionally, the drokpas divert the risk of snowstorms and droughts by dispersing their herds among those of their relatives or friends.  The arrangement that less drokpas now occupy the pastures will disturb such traditional risk aversion method.  The ranch manager without nearby relatives/friends to help him/her will inevitably rely singly on the state's aid in case of disasters.  This may reduce the system's resilience.

It is also doubtful whether the new Third Industry staffed by drokpas is sustainable.  Due to the economic development in Tibet at this moment, the Third Industry will mainly serve people from outside.  This will bring currency to the region.  But the limited income, except for several large cities, cannot be invested in other means than self-sustaining.  Based on tourism only, without the support of the First and Second Industry, such Third Industry may swarm in large cities, living small cities and towns deprived of labour.  Thus the gap between richer and poorer counties may be widened.

I still do not know to what extent has this policy being carried out and what are the effects.  I will take this question along with me in the field and seek answers.

2007年3月19日星期一

Restocking and Settling Nomads Following Severe Snowstorms

Restocking and Settling Nomads Following Severe Snowstorms

As a chapter in a book this article is especially useful to me and perhaps many other nomadism students.   It provides some perspectives on snowstorms, and traditional Tibetan pastoralism.  It discussed about some common fallacies hold by the mass and the authorities over the nomadism in Tibet.

Of more value, the article introduced the historical changes taken place in Tibetan pastoralism in the past decades, as well as information on a few past snowstorms, which will surely help my project.