打开/关闭搜索
搜索
打开/关闭菜单
60
73
29
1.1K
武外梗百科
导航
首页
最近更改
随机页面
站务
其他
友链
特殊页面
打开/关闭外观设置菜单
通知
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
讨论
贡献
创建账号
登录
编辑“︁
Module:PageSummary
”︁
武外梗百科 爱国好学自强图新的百科全书
查看
阅读
编辑源代码
查看历史
associated-pages
模块
讨论
更多操作
Zelda110
(
留言
|
贡献
)
2025年12月21日 (日) 17:24的版本
(
差异
)
←上一版本
|
最后版本
(
差异
) |
下一版本→
(
差异
)
警告:您正在编辑该页面的旧版本。
如果您发布该更改,该版本后的所有更改都会丢失。
警告:
您没有登录。如果您进行任何编辑,您的IP地址会公开展示。如果您
登录
或
创建账号
,您的编辑会以您的用户名署名,此外还有其他益处。
反垃圾检查。
不要
加入这个!
local p = {} function p.getSummaryAndImage(frame) local pageName = frame.args[1] or "" local title = mw.title.new(pageName) if not title or not title.exists then return "页面不存在" end local content = title:getContent() -- 1. 提取第一张图 local firstImage = string.match(content, "%[%[([Ff]ile:.-)[|%]]") or string.match(content, "%[%[([Ii]mage:.-)[|%]]") or string.match(content, "%[%[(文件:.-)[|%]]") or string.match(content, "%[%[(图像:.-)[|%]]") -- 2. 清理正文并处理截断(逻辑保留) local cleanText = content cleanText = string.gsub(cleanText, "<ref.-</ref>", "") cleanText = string.gsub(cleanText, "<ref.->", "") cleanText = string.gsub(cleanText, "<!%-%-.-%-%->", "") cleanText = string.gsub(cleanText, "%[%[[Ff]ile:.-%]%]", "") cleanText = string.gsub(cleanText, "%[%[[Ii]mage:.-%]%]", "") cleanText = string.gsub(cleanText, "%[%[文件:.-%]%]", "") cleanText = string.gsub(cleanText, "%[%[图像:.-%]%]", "") local limit = 10 while string.find(cleanText, "{{.-}}") and limit > 0 do cleanText = string.gsub(cleanText, "{{[^{}]+}}", "") limit = limit - 1 end cleanText = mw.text.trim(cleanText) cleanText = string.gsub(cleanText, "\n", " ") local targetLen = 100 local summary = "" if mw.ustring.len(cleanText) <= targetLen then summary = cleanText else summary = mw.ustring.sub(cleanText, 1, targetLen) local restText = mw.ustring.sub(cleanText, targetLen + 1) -- 链接延展处理 local lastOpen = 0 local lastClose = 0 local tempPos = 0 while true do local found = string.find(summary, "%[%[", tempPos + 1) if not found then break end lastOpen = found tempPos = found end tempPos = 0 while true do local found = string.find(summary, "%]%]", tempPos + 1) if not found then break end lastClose = found tempPos = found end if lastOpen > lastClose then local endOfLink = string.find(restText, "%]%]") if endOfLink then summary = summary .. string.sub(restText, 1, endOfLink + 1) end end summary = summary .. "..." end -- === 3. 维基百科风格渲染 === -- 外层容器:高斯模糊边框、悬停变色、白色底 local container = mw.html.create('div') :css({ ['margin'] = '10px 0', ['background'] = '#fff', ['border'] = '1px solid #a2a9b1', -- 标准维基百科灰框色 ['border-radius'] = '2px', ['display'] = 'flex', -- 使用 Flex 布局实现响应式 ['flex-direction'] = 'row-reverse', -- 图片在右,文字在左 ['overflow'] = 'hidden', ['box-shadow'] = '0 1px 1px rgba(0,0,0,0.05)', ['min-height'] = '120px' }) -- 图片部分 if firstImage then container:tag('div') :css({ ['flex-shrink'] = '0', ['width'] = '140px', ['background-color'] = '#f8f9fa', ['display'] = 'flex', ['align-items'] = 'center', ['justify-content'] = 'center', ['border-left'] = '1px solid #a2a9b1' }) :wikitext('[[' .. firstImage .. '|140x140px|center|link=' .. pageName .. ']]') end -- 文字内容部分 local textCol = container:tag('div') :css({ ['padding'] = '12px 16px', ['flex-grow'] = '1', ['display'] = 'flex', ['flex-direction'] = 'column', ['justify-content'] = 'center' }) -- 标题(维基经典的衬线体或加粗体) textCol:tag('div') :css({ ['font-size'] = '1.2em', ['font-weight'] = 'bold', ['margin-bottom'] = '5px', ['color'] = '#000' }) :wikitext('[[' .. pageName .. ']]') -- 摘要文本 textCol:tag('div') :css({ ['font-size'] = '0.92em', ['line-height'] = '1.5', ['color'] = '#202122' -- 维基百科标准正文黑色 }) :wikitext(summary) return tostring(container) end return p
摘要:
请注意,所有对武外梗百科的贡献均可能会被其他贡献者编辑、修改或删除。如果您不希望您的文字作品被随意编辑,请不要在此提交。
您同时也向我们承诺,您提交的内容为您自己所创作,或是复制自公共领域或类似自由来源(详情请见
武外梗百科:著作权
)。
未经许可,请勿提交受著作权保护的作品!
取消
编辑帮助
(在新窗口中打开)
预览使用本模板的页面
该页面使用的模板:
Module:PageSummary/doc
(
编辑
)
编辑“︁
Module:PageSummary
”︁
武外梗百科 爱国好学自强图新的百科全书