Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make post's representation change when posts change
  • Loading branch information
ralsina committed May 14, 2015
1 parent 0882356 commit 7b6a984
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/manual.txt
Expand Up @@ -1659,7 +1659,8 @@ Post List
every time a post is added or deleted, causing maybe unnecessary rebuilds.

On the other hand, it will sometimes **not** be considered out of date if
a post title or content changes, so it can sometimes be shown outdated.
a post content changes, so it can sometimes be shown outdated, in those
cases, use ``nikola build -a`` to force a total rebuild.


This directive can be used to generate a list of posts. You could use it, for
Expand Down
9 changes: 8 additions & 1 deletion nikola/post.py
Expand Up @@ -29,6 +29,8 @@
import io
from collections import defaultdict
import datetime
import hashlib
import json
import os
import re
import string
Expand Down Expand Up @@ -229,7 +231,12 @@ def __init__(
self.compiler.register_extra_dependencies(self)

def __repr__(self):
return '<Post: {0}>'.format(self.source_path)
# Calculate a hash that represents most data about the post
m = hashlib.md5()
# source_path modification date (to avoid reading it)
m.update(str(os.stat(self.source_path).st_mtime))
m.update(json.dumps(self.meta, cls=utils.CustomEncoder, sort_keys=True))
return '<Post: {0} {1}>'.format(self.source_path, m.hexdigest())

def _has_pretty_url(self, lang):
if self.pretty_urls and \
Expand Down
2 changes: 1 addition & 1 deletion nikola/utils.py
Expand Up @@ -57,7 +57,7 @@

from nikola import DEBUG

__all__ = ['get_theme_path', 'get_theme_chain', 'load_messages', 'copy_tree',
__all__ = ['CustomEncoder', 'get_theme_path', 'get_theme_chain', 'load_messages', 'copy_tree',
'copy_file', 'slugify', 'unslugify', 'to_datetime', 'apply_filters',
'config_changed', 'get_crumbs', 'get_tzname', 'get_asset_path',
'_reload', 'unicode_str', 'bytes_str', 'unichr', 'Functionary',
Expand Down

2 comments on commit 7b6a984

@Kwpolska
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use for this __repr__ change? Is there no better place to do this in?

@ralsina
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want Nikola.timeline to change when posts content and/or metadata change.

Please sign in to comment.