Module:ProjectGallery: Difference between revisions

From Makerpedia

EvaC (talk | contribs)
Created page with "local p = {} function p.generateGallery(frame) local category = "Projects" local pages = mw.site.categoryMembers(category, "all") -- Get all project pages local gallery = {} for _, page in ipairs(pages) do local title = page.title local content = mw.title.new(title):getContent() local img = content and content:match("img1=(https://[^\n|}%s]+)") or nil if img then table.insert(gallery, string.format(..."
 
EvaC (talk | contribs)
No edit summary
 
(One intermediate revision by the same user not shown)
Line 13: Line 13:
         if img then
         if img then
             table.insert(gallery, string.format(
             table.insert(gallery, string.format(
                'File:%s|link=%s|alt=%s|thumb|200px|<center>[[%s]]</center>',
'
[[File:%25s|link=%s|alt=%s|thumb|200x200px|<center>[[%s]]</center>]]
',
                 img, title, title, title
                 img, title, title, title
             ))
             ))
         end
         end
     end
     end
return '<gallery>
File:\n'_.._table.concat(gallery,_"\n")_.._'\n
</gallery>'


    return '<gallery>\n' .. table.concat(gallery, "\n") .. '\n</gallery>'
end
end


return p
return p

Latest revision as of 18:15, 8 February 2025

local p = {}

function p.generateGallery(frame)

   local category = "Projects"
   local pages = mw.site.categoryMembers(category, "all") -- Get all project pages
   local gallery = {}
   for _, page in ipairs(pages) do
       local title = page.title
       local content = mw.title.new(title):getContent()
       local img = content and content:match("img1=(https://[^\n|}%s]+)") or nil
       if img then
           table.insert(gallery, string.format(

'

%s
%s

',

               img, title, title, title
           ))
       end
   end

return '

'

end

return p