Mô đun:Transclude DYK

local p = {}

-- Transclude randomly selected "Did you know?" entries
function p.main(frame)
	-- args = { 1,2,... = page names, paragraphs = list e.g. "1,3-5", files = list, more = text}
	local args = {} -- args[k] = frame.args[k] or frame:getParent().args[k] for all k in either (numeric or not)
	for k, v in pairs(frame:getParent().args) do args[k] = v end
	for k, v in pairs(frame.args) do args[k] = v end -- args from a Lua call have priority over parent args from template

	-- Read the input page
	local page = args[1] or error("Không có tên trang cho")
	local title = mw.title.new(page) or error("Thiếu trang đầu vào " .. page)
	local text = title:getContent() or error("Không có nội dung cho trang " .. page)

	-- Limit to the DYK section if present
	local sectionstart = mw.ustring.find(text, "\n==Bài viết ''Bạn có biết không?''==", 1, true)
	if sectionstart then
		local sectionend = mw.ustring.find(text, "\n==", sectionstart + 1, true) or -1
		text = mw.ustring.sub(text, sectionstart, sectionend)
	end

	-- Parse the entries
	entries = {}
	for entry in mw.ustring.gmatch(text, "\n%*[.…%s]*([^\n]+)") do
		if not mw.ustring.find(entry, "trang thảo luận của bài viết thiếu lời giới thiệu chủ đề", 1, true) then
			table.insert(entries, entry)
		end
	end

	-- Swap some random entries into the first n positions
	local n = math.min(#entries, args.count or 10) -- the number of entries to produce
	math.randomseed(os.time())
	for i = 1, n do
		j = math.random(i, #entries)
		entries[i], entries[j] = "*... " .. entries[j], entries[i]
	end

	-- Return the first n entries
	text = table.concat(entries, "\n", 1, n)
	return frame:preprocess(text)
end

return p
Chúng tôi bán
Bài viết liên quan
Giới thiệu Level Up: Gaming Gò Gai, Thủy Nguyên, Hải Phòng
Giới thiệu Level Up: Gaming Gò Gai, Thủy Nguyên, Hải Phòng
Một quán net sạch sẽ và chất lượng tại Thủy Nguyên, Hải Phòng bạn nên ghé qua
Vì sao cảm xúc quan trọng đối với quảng cáo?
Vì sao cảm xúc quan trọng đối với quảng cáo?
Cảm xúc có lẽ không phải là một khái niệm xa lạ gì đối với thế giới Marketing
Bí thuật đưa hình ảnh Starbucks leo đỉnh của chuỗi đồ uống
Bí thuật đưa hình ảnh Starbucks leo đỉnh của chuỗi đồ uống
Các công ty dịch vụ từ nhỏ đến lớn, từ vi mô đến vĩ mô bắt đầu chú trọng hơn vào việc đầu tư cho hình ảnh và truyền thông
Nhân vật Geto Suguru - Jujutsu Kaisen
Nhân vật Geto Suguru - Jujutsu Kaisen
Geto Suguru (夏げ油とう傑すぐる Getō Suguru?, Hạ Du Kiệt) là một phản diện trong bộ truyện Chú thuật hồi chiến và tiền truyện Chú thuật hồi chiến - Trường chuyên chú thuật Tokyo