Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactoring to remove duplicated code.

I didn't realize that code in VPStaticExportScript was visible to other
scriptlets. Added pubDateForItem in VPStaticExportScript which is now
called from staticExportArchivePathForItem and used by
VPStaticPageEntryTemplate.
  • Loading branch information...
commit 1e1c60abc63a592890bb0993b9db93d3a745deb7 1 parent f8a0586
@pwc3 pwc3 authored
View
42 plugins-bundle/Static/Static/VPStaticExportScript.jstalk
@@ -49,6 +49,28 @@ function staticExportDidAppendItemToFrontPage(document, item, frontPageMutableSt
}
function staticExportArchivePathForItem(document, item, fileName, staticSetup) {
+ var components = [[NSCalendar currentCalendar] components:NSMonthCalendarUnit | NSYearCalendarUnit fromDate:pubDateForItem(item)];
+
+ var year = [components year];
+ var month = [components month];
+
+ return "archives/" + year + "/" + month + "/" + fileName;
+}
+
+function staticExportArchivePathForAssetItem(document, item, fileName, staticSetup) {
+ return "assets/" + fileName;
+}
+
+
+/*
+ Use this function to return a list of pages (as an array) that you want written out at the root of the export directory.
+ */
+function staticSupportPages(document, staticSetup) {
+ //return ["about", "contact"]
+ return [];
+}
+
+function pubDateForItem(item) {
var pubDate = null;
// if there is a pubdate set in the Page Meta, use it for the publish date
@@ -67,24 +89,6 @@ function staticExportArchivePathForItem(document, item, fileName, staticSetup) {
{
pubDate = [item createdDate];
}
-
- var components = [[NSCalendar currentCalendar] components:NSMonthCalendarUnit | NSYearCalendarUnit fromDate:pubDate];
-
- var year = [components year];
- var month = [components month];
-
- return "archives/" + year + "/" + month + "/" + fileName;
-}
-function staticExportArchivePathForAssetItem(document, item, fileName, staticSetup) {
- return "assets/" + fileName;
-}
-
-
-/*
- Use this function to return a list of pages (as an array) that you want written out at the root of the export directory.
- */
-function staticSupportPages(document, staticSetup) {
- //return ["about", "contact"]
- return [];
+ return pubDate;
}
View
22 plugins-bundle/Static/Static/VPStaticPageEntryTemplate.html
@@ -4,30 +4,10 @@
"page" - this var represents the given entry, it's a VPData object.
"pageContext" - this is a dictionary, which currently has the keys pageArchivePath (relative path for this file) and pageEntry (the rendered HTML for the page)
*/
-
- var pubDate = null;
-
- // if there is a pubdate set in the Page Meta, use it for the publish date
- var pubDateStr = [page metaValueForKey:"pubdate"];
- if (pubDateStr)
- {
- var parser = [[NSDateFormatter alloc] init];
- [parser setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- pubDate = [parser dateFromString:pubDateStr];
- // if the date couldn't be parsed, pubDate will remain null
- [parser release];
- }
-
- // fall back to the page's createdDate
- if (pubDate == null)
- {
- pubDate = [page createdDate];
- }
-
// setup some fancy formatting for this guy's publish date.
var formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateStyle:NSDateFormatterMediumStyle];
- var displayDate = [formatter stringFromDate:pubDate];
+ var displayDate = [formatter stringFromDate:pubDateForItem(page)];
%>
<div class="post">
Please sign in to comment.
Something went wrong with that request. Please try again.