Module:All authors

From The Observatory

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

local p = {}

function p.list(frame)

	local showbadges = false
	local html = mw.html.create()
	local authors = mw.smw.ask {
		'[[Category:Authors]]',
		'mainlabel=-',
		'?#-=page',
		'?Display title of=name',
		'?Sort as=sort_as',
		'?Has photo#-=photo',
		'?Role=role',
		'limit=500',
		'searchlabel=',
		'order=asc'
	}
	
	local sideblock = html:tag('div')
    :attr('id', 'article-authors')
    :addClass('mt-0')
    :css('flex', '0 0 280px')
    :wikitext()
    
	local tiles = sideblock:tag('table')
		:attr('id', 'listauthors')
		:addClass('observatory-tile-deck')

    for _, author in ipairs(authors) do

        local count = mw.smw.ask {
            '#ask',
            '[[Category:Articles]][[Text author::' .. author['page'] .. ']]',
            'format=count'
        } or 0
        
        local name = author['name'] or author['page']
        local sortas = author['sort_as'] or author['name'] or author['page']

        if tonumber(count) > 0 then 
            local item = tiles:tag('tr')
           	    :addClass('tile d-flex align-items-center gap-3 bg-transparent')

            local item_label = item:tag('td')
            	:attr('data-sort', sortas)
            	:addClass('tile-caption d-flex justify-content-between align-items-center w-100 p-0')
             	:wikitext('[[' .. author['page'] .. '|' .. name .. ']]')

			if showbadges then
            	item_label:tag('div')
                	:addClass('badge badge-light')
                	:wikitext(count)
			end
        
         end
    end
    local cardwall = html:tag('div')
    	:addClass('d-flex w-100 flex-wrap')
    	:attr('id', 'author-cards')
    	:css({
    		['gap'] = '1rem'
    	})
    for _, author in ipairs(authors) do
    	
    	local page = author['page']
    	local name = author['name'] or author['page']
        local sortas = author['sort_as'] or author['name'] or author['page']
		local photo = author['photo'] or 'Observatory_Logo_for_Writers_bg.png'
        local url = frame:preprocess('{{filepath:{{PAGENAME:' .. photo .. '}}}}')
        local roles = author['role'] or ''
        if type(roles) == 'table' then
        	roles = table.concat(roles, ", ")
        end
        
    	local card = cardwall:tag('div')
    		:addClass('card text-center border-0')
    		:attr('data-sort', sortas)
    		:css({
    			['flex'] = '1 1 240px'
    		})
    		
    		card:tag('div')
    			:addClass('card-img-top')
    			:attr('data-bg', url)

    		card:tag('div')
    			:addClass('card-footer rounded-bottom interface font-weight-bold ' .. page)
    			:wikitext(string.format('[[%s|%s]]'
    				, page
    				, name
    			))
    			:tag('div')
    				:addClass('small')
    				:wikitext(roles)
    end
    
	return html
end

return p