1 # ===================================================================== 2 # pageRelatedPages.awk: W-TW list related pages, based on tags. 3 # 4 # Copyright (c) 2009-2011 Carlo Strozzi 5 # 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; version 2 dated June, 1991. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 # 19 # ===================================================================== 20 21 BEGIN { 22 23 fmt = tmp = sep = ""; delete a; delete e; delete f 24 25 # build links to related pages. 26 27 fmt = readfmt("tw-page-related") 28 gsub(/%/,"%%",fmt) # turn plain '%' into '%%'. 29 gsub(/\\/,"\\\\&",fmt) # turn '\' into '\\'. 30 gsub(/[\n\r]+/,"",fmt) # just in case. 31 tmp = fmt 32 33 # Handle custom positioning of output tokens. 34 sub(/.*\[:/,_NULL,tmp); sub(/:].*/,_NULL,tmp) 35 tmp = _strip(tmp,_O_MIDDLE) 36 if (tmp !~ /^[0-2 ]+$/) tmp = "1 2" 37 38 # pad missing arg specs with "0". 39 if ((i=split(tmp,f," ")) < 2) { 40 while (i++ <= 2) tmp = tmp " 0" 41 i = split(tmp,f," ") 42 } 43 44 tmp = _NULL 45 46 for (j=1; j<=i; j++) { 47 if (j > 2) break # ignore excess arg specs. 48 if (!sub(//,"%s",fmt)) fmt = fmt "" 49 tmp = tmp " " f[j] 50 } 51 52 # encode any extra markers. 53 gsub(//,"\\<tw:s/\\>",fmt) 54 55 fmt = fmt "\n" 56 57 split(_strip(tmp),f," "); f[0] = 0 58 59 g_name = _rcget("tbl_group.g_name") 60 g_uri = _rcget("tbl_group.g_uri") 61 62 if (!(trunc=_rcget("TNS_RELATED_PAGES_PROP",2))) trunc = 10 63 64 e[0] = _NULL 65 66 print "" # documentation. 67 } 68 69 /^\001/ { trunc++; next } # skip table header, if any. 70 71 NR > trunc { exit } 72 73 { 74 # k_tag, k_page, tag_page 75 76 split($0,a,"\t") 77 78 # By default, display only about 30 chars of visible link title, 79 # or it may overflow the side-bar where these things are usually 80 # placed. 81 82 if (!(tmp=_rcget("TNS_RELATED_PAGES_PROP",3))) tmp = 23 83 84 # Set default subcat separator on visible link names. 85 if ((sep=_rcget("TNS_RELATED_PAGES_PROP",1)) == _NULL) sep = "." 86 87 if (substr(a[3],tmp) != "") dots = " ..." 88 else dots = "" 89 90 # Replace subcat separator with customized value, if defined. 91 if (getcat(a[3]) != _NULL) sub(/\./,sep,a[3]) 92 93 e[1] = ENVIRON["CSA_RPC_URI"] "/" \ 94 ENVIRON["CSA_LANG"] "/" g_uri "/" a[2] 95 e[2] = _xmlencode(substr(a[3],1,tmp-1) dots) 96 printf(fmt,e[f[1]],e[f[2]]) 97 } 98 99 # EOF