Module:长标题
跳到导航
跳到搜索
local module = {} local array = require('Module:var-array') function module.main(frame) local data = array.get('长标题'); -- mw.logObject(data[0]) local item = {}; function len(a) local rlt = 0; for i = 1, mw.ustring.len(a) do local char = mw.ustring.sub(a, i, i); local charnum = mw.ustring.byte(char); if (charnum > 33 and charnum < 126) or char == '‘' or char == '’' or char == '“' or char == '”' or char == '「' or char == '」' or char == '《' or char == '》' or char == '(' or char == ')' or char == '【' or char == '】' or char == '{' or char == '}' then rlt = rlt + 0.5; elseif char == ' ' or char == ' ' or char == '\n' or char == '\t' then -- do nothing else rlt = rlt + 1; end end return rlt; end function cmp (a, b) return a.len > b.len; end for i = 1, #data do local sort_key = data[i][1]:gsub('<%s-/?del.->', ''):gsub('<%s-/?span.->', ''); if (string.match(sort_key, '^%[%[.-%|(.-)%]%]$')) then sort_key = string.match(sort_key, '%[%[.-%|(.-)%]%]'); elseif (string.match(sort_key, '^%[%[(.-)%]%]$')) then sort_key = string.match(sort_key, '^%[%[(.-)%]%]$'); end -- mw.log(sort_key); local length; if (data[i][5] ~= nil and data[i][5] ~= '') then length = tonumber(data[i][5]); else length = len(sort_key); end -- mw.log(data[i][5]); table.insert(item, { name=data[i][1], short=data[i][2], theme=data[i][3], original_number=data[i][4], len=length }) end table.sort(item, cmp) local rlt = ''; for i = 1, #item do rlt = rlt..'|-\n|'..item[i].name..'||'..item[i].short..'||<span class="long-title-theme">'..item[i].theme..'</span>||'..item[i].original_number..'||'..item[i].len..'\n' end return rlt..'\n|}'; end return module