-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfendo.addon.linked_file_size.fs
94 lines (66 loc) · 2.49 KB
/
fendo.addon.linked_file_size.fs
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
.( fendo.addon.linked_file_size.fs) cr
\ This file is part of Fendo
\ (http://programandala.net/en.program.fendo.html).
\ This file adds the file size to all file links.
\ Last modified 202011160218.
\ See change log at the end of the file.
\ Copyright (C) 2013,2017,2019 Marcos Cruz (programandala.net)
\ Fendo is free software; you can redistribute
\ it and/or modify it under the terms of the GNU General
\ Public License as published by the Free Software
\ Foundation; either version 2 of the License, or (at your
\ option) any later version.
\ Fendo is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied
\ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\ PURPOSE. See the GNU General Public License for more
\ details.
\ You should have received a copy of the GNU General Public
\ License along with this program; if not, see
\ <http://gnu.org/licenses>.
\ Fendo is written in Forth (http://forth-standard.org)
\ with Gforth (http://gnu.org/software/gforth).
\ ==============================================================
1024 constant KiB
KiB dup * constant MiB
: >linked_file_size ( n -- ca len )
s>d <# # # '.' hold #s #> ;
: echo_linked_file_size_MiB ( n -- )
100 * MiB / >linked_file_size echo s" MiB" _echo ;
: echo_linked_file_size_KiB ( n -- )
100 * KiB / >linked_file_size echo s" KiB" _echo ;
: echo_linked_file_size_B ( n -- )
echo. s" B" _echo ;
: echo_linked_file_size ( n -- )
dup MiB >= if echo_linked_file_size_MiB exit then
dup KiB >= if echo_linked_file_size_KiB exit then
echo_linked_file_size_B ;
: (linked_file_size) ( -- )
s" (" _echo
last_href$ $@ -file:// file>local
slurp-file nip echo_linked_file_size
s" )" echo ;
: linked_file_size ( -- )
file_link? if (linked_file_size) then ;
' linked_file_size is link_text_suffix
\ Set the hook.
\ doc{
\
\ linked_file_size ( -- )
\
\ An alternative action for `link_text_suffix`. It adds the file
\ size to file links.
\
\ Usage example (note this is already done when the addon of
\ ``linked_file_size`` is loaded):
\ ----
\ ' linked_file_size is link_text_suffix
\ ----
\ }doc
.( fendo.addon.linked_file_size.fs compiled) cr
\ ==============================================================
\ Change log {{{1
\ 2019-03-21: Move the code from the application Fendo-programandala
\ (which builds http://programandala.net), in order to reuse it in
\ other sites. Update source style. Document.
\ vim: filetype=gforth