مۆدیوول:Navseasoncats/var firsthalf
بەڵگەدارکردنی مۆدیوول[دروست بکە]
لەوانەیە بتەوێ پەڕەیەکی بەڵگەدارکردن بۆ ئەم مۆدیوولی سکریبونتۆیە دروست بکەی. دەستکاریکەران دەتوانن ئەم مۆدیوولە لە پەڕەکانی خۆڵەپەتانێ (دروست بکە | ئاوێنە) و ئەزموون (دروست بکە) تاقی بکەنەوە. تکایە پۆلەکان بە ژێرپەڕەی /doc زیاد بکە. ژێرپەڕەکانی ئەم مۆدیوول. |
local p = {}
function p.var_firsthalf(frame)
--Extracts the part of the string before the year
local arg, pagename, titleyear = nil
if frame.args[1] then arg = mw.text.trim(frame.args[1]) end
if arg and arg ~= '' then
pagename = arg
titleyear = frame:expandTemplate{ title = 'Title year', args = { page = pagename } }
else
pagename = mw.title.getCurrentTitle().text
titleyear = frame:expandTemplate{ title = 'Title year', args = { pagename } }
end
local strleft4 = string.match(pagename, '^[%d%D]?[%d%D]?[%d%D]?[%d%D]?')
if strleft4 == titleyear then
return ''
else
local pos = mw.ustring.find( pagename, titleyear, 1, true ) or 0
local posm2 = pos - 2
local out = frame:expandTemplate{ title = 'Str left', args = { pagename, posm2 } }
return mw.text.trim(out)
end
end
return p