Module:Sandbox/Ahecht/Xviews: Difference between revisions

Content deleted Content added
debug
debug
Line 3:
local function ifblank(v, alt) return notblank(v) and v or alt end
local function red(v) return '<span style="color: red;">' .. v .. '</span>' end
local function getContent(page) return mw.ustringstring.gsub(mw.title.new(page).content, '^Date,"[^"]+"', '') end
local function diffDays(dargs)
return require('Module:diff days')['diff_days'](
Line 53:
 
function p._nthView(page, number) -- {{xviews/nth view}}
local views = mw.ustringstring.gsub(getContent(page), '.?(202%d%-%d%d%-%d%d)%,?(%d+)', '%1:%2,')
return Text.split(views, ',', true)[tonumber(number)]
end
Line 64:
 
function p._viewCount(page) -- {{xviews/view count}}
local str = mw.ustringstring.gsub(getContent(page), '.?202%d%-%d%d%-%d%d', '')
str = mw.ustringstring.gsub(str, ',', '', 1)
-- Remove leading and trailing delimiters (along with any surrounding whitespace)
str = str:gsub("^%s*,%s*", ""):gsub("%s*,%s*$", "")
Line 157:
function p._xlabel(date, bold01) -- {{xviews/xlabel}}
replace = ((date:sub(-3) == '-01') and notblank(bold01)) and "'''%1'''" or "%1"
return mw.ustringstring.gsub(date, '20[23]%d%-(%d%d%-%d%d)', replace)
end
function p.xlabel(frame)
Line 165:
function p._maxViews(page) -- {{xviews/max views}}
local views = 0
forlocal vcontent in= Textstring.gsplitgsub(getContent(page), ',.?202%d%-%d%d%-%d%d', true'') do
for v in Text.gsplit(content, ',', true) do
v = tonumber(v)
if (v and v > views) then views = v end