Changes

Jump to navigation Jump to search
209 bytes added ,  13:16, 22 April 2021
no edit summary
Line 1: Line 1:  
local sb = {} -- functions package for HPB Scrapbooks
 
local sb = {} -- functions package for HPB Scrapbooks
   −
function sb.item_id( frame )
+
function sb.item_id2( frame )
 
local id = frame.args['volume'] .. '-' .. frame.args['page'] .. '-' .. frame.args['item']
 
local id = frame.args['volume'] .. '-' .. frame.args['page'] .. '-' .. frame.args['item']
 
     return id
 
     return id
 
end
 
end
   −
function sb.item_id2( frame )
+
-- Create unique ID for the item, which consist of: Volume-Page-Item_on_page
 +
-- ID example: 01-017-03
 +
-- Call example: {{#invoke: SB | item_id | volume=1 | page=17 | item=3 }}
 +
-- Values: volume=1..99, page=1..999, item=1..99
 +
function sb.item_id( frame )
 
local vNum = string.format("%.2d", frame.args['volume'])
 
local vNum = string.format("%.2d", frame.args['volume'])
 
local iNum = string.format("%.2d", frame.args['item'])
 
local iNum = string.format("%.2d", frame.args['item'])
--print(vNum)
   
local p_int, p_frac = math.modf(frame.args['page'])
 
local p_int, p_frac = math.modf(frame.args['page'])
 
local pNum = string.format("%.3d", p_int)   
 
local pNum = string.format("%.3d", p_int)   
 +
 +
--mw.log('int= '.. p_int .. ', frac= ' .. p_frac)
 
if p_frac > 0 then
 
if p_frac > 0 then
pNum = pNum .. '.' .. p_frac
+
str = tostring(p_frac)
 +
pNum = pNum .. '.' .. string.sub(str,3,5)
 
end
 
end
+
 
--local id = string.format("%.2d", frame.args['volume']) .. '-' .. pNum .. '-' .. iNum
+
local id = vNum .. '-' .. pNum .. '-' .. iNum
local id = vNum .. '--' .. pNum .. '--' .. iNum
   
return id
 
return id
 
end
 
end

Navigation menu