Jump to content

Module:Pag

From Wikisource

Documentation for this module may be created at Module:Pag/doc

local p = {}

-- in nsPage gets a book page number and returns a link to matching nsPage page 
function p.b2dt(frame)
   local base = mw.title.getCurrentTitle()
   local pageData="Module:Data/"..base.rootText
   local pages = mw.loadData(pageData)
   frame=frame:getParent()
   result=pages.b2d[frame.args[1]]
   return result
end

-- in ns0 gets a book page number and returns a link to matching ns0 page pointed to the anchor of transcluded djvu page
function p.b2ns0(frame)
   local title=mw.title.getCurrentTitle()
   local text=title:getContent()
   local pageData="Module:Data/"..string.match(text,'index="([^"]-)"')
   local pages=mw.loadData(pageData)
   frame=frame:getParent()
   positionSource=pages.b2d[frame.args[1]]
   for i,v in pairs(pages.cap) do
      if positionSource>= v.from and positionSource<=v.to
	then
           return v.name.."#"..pages.d2b[positionSource]
        end
   end
   return positionSource 
end
-- in ns0 returns the index of any of the sub-chapters
function p.index(frame)
   local title=mw.title.getCurrentTitle()
   local text=title:getContent()
   local pageData="Module:Data/"..string.match(text,'index="([^"]-)"')
   
   local pages=mw.loadData(pageData)
   local text="== INDEX ==\n"
   local y=0
   for i,v in pairs(pages.cap) do
       subchapter=string.match(v.name,title.text.."/(.+)")
       if subchapter ~= nil then
          subchapter,y=string.gsub(subchapter,"/","/")
          text=text..string.rep("*",y+1).." ''[["..v.name.."|"..v.title.."]]''\n"
       end    
   end
   if text=="== INDEX ==\n" then 
       text=""
    end
    return text   
end
   
return p