~sungo/nanoblogger

ref: f4d47f3be478b1486741e06891078be1048837e9 nanoblogger/plugins/recent_entries.sh -rw-r--r-- 1.8 KiB
f4d47f3b — sungo change powered and generator links to my repo 1 year, 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# NanoBlogger Recent Entries List Plugin
# List Recent entries
#
# sample code for templates, based off the default stylesheet
#
# <div class="sidetitle">
# Recent Entries/Alternate Entries
# </div>
# <div class="side">
# $NB_Recent_Entries/$NB_Alterate_Entries
# </div>

# set how many entries to list
: ${RECENTLIST_ENTRIES:=10}
: ${RECENTLIST_OFFSET:=1}
: ${RECENTLIST_QUERYMODE:=max}

PLUGIN_OUTFILE1="$BLOG_DIR/$PARTS_DIR/recent_entries.$NB_FILETYPE"
PLUGIN_OUTFILE2="$BLOG_DIR/$PARTS_DIR/alternate_entries.$NB_FILETYPE"

# always sort in reverse chronological order so recent entries
# stay near the top of the list
if [ "$CHRON_ORDER" != 1 ]; then
	RECENTLIST_SORTARGS="-ru"
else
	RECENTLIST_SORTARGS=
fi

nb_msg "$plugins_action recent entries links ..."
set_baseurl "./"

get_entries(){
case "$1" in
	new)
		query_db "$RECENTLIST_QUERYMODE" nocat limit "$RECENTLIST_ENTRIES" "" "$RECENTLIST_SORTARGS"
		;;
	alt)
		let XRECENTLIST_OFFSET=${RECENTLIST_ENTRIES}+1
		XRECENTLIST_ENTRIES=$RECENTLIST_ENTRIES
		query_db "$RECENTLIST_QUERYMODE" nocat limit "$XRECENTLIST_ENTRIES" "$XRECENTLIST_OFFSET" "$RECENTLIST_SORTARGS"
		;;
esac
RECENTLIST_DBRESULTS=(${DB_RESULTS[*]})
for entry in ${RECENTLIST_DBRESULTS[*]}; do
	# 1st try to get title from set_entrylink instance of read_metadata
	link_title="$smartlink_metatitle"
	if [ -z "$link_title" ]; then
		read_metadata TITLE "$NB_DATA_DIR/$entry"
		link_title="$METADATA"
	fi
	NB_EntryID=$x_id${entrylink_var//[\/]/-}
	[ -z "$link_title" ] && link_title="$notitle"
	set_entrylink "$entry"
	echo '<a href="'${ARCHIVES_PATH}$NB_EntryPermalink'">'$link_title'</a><br />'
done
}

get_entries new > "$PLUGIN_OUTFILE1"
NB_RecentEntries=$(< "$PLUGIN_OUTFILE1")

# uncomment to create alternate entry listing
#get_entries alt > "$PLUGIN_OUTFILE2"
#NB_AlternateEntries=$(< "$PLUGIN_OUTFILE2")