Module:PageSummary:修订间差异
武外梗百科 爱国好学自强图新的百科全书
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第8行: | 第8行: | ||
local content = title:getContent() | local content = title:getContent() | ||
-- 1. | -- 1. 提取第一张图(用于单独在右侧显示) | ||
local firstImage = string.match(content, "%[%[([Ff]ile:.-)[|%]]") or | local firstImage = string.match(content, "%[%[([Ff]ile:.-)[|%]]") or | ||
string.match(content, "%[%[([Ii]mage:.-)[|%]]") or | string.match(content, "%[%[([Ii]mage:.-)[|%]]") or | ||
| 第15行: | 第14行: | ||
string.match(content, "%[%[(图像:.-)[|%]]") | string.match(content, "%[%[(图像:.-)[|%]]") | ||
-- 2. | -- 2. 彻底清理正文(去除所有图片、模板、引用) | ||
local cleanText = content | local cleanText = content | ||
-- | |||
-- 核心:彻底去除摘要文本中所有的图片标记 | |||
-- 使用更严谨的匹配:从 [[File: 开始,匹配到第一个不被嵌套的 ]] | |||
cleanText = string.gsub(cleanText, "%[%[[Ff]ile:.-%]%]", "") | cleanText = string.gsub(cleanText, "%[%[[Ff]ile:.-%]%]", "") | ||
cleanText = string.gsub(cleanText, "%[%[[Ii]mage:.-%]%]", "") | cleanText = string.gsub(cleanText, "%[%[[Ii]mage:.-%]%]", "") | ||
| 第23行: | 第24行: | ||
cleanText = string.gsub(cleanText, "%[%[图像:.-%]%]", "") | cleanText = string.gsub(cleanText, "%[%[图像:.-%]%]", "") | ||
-- | -- 移除其余干扰项 | ||
cleanText = string.gsub(cleanText, "<ref.-</ref>", "") | cleanText = string.gsub(cleanText, "<ref.-</ref>", "") | ||
cleanText = string.gsub(cleanText, "<ref.->", "") | cleanText = string.gsub(cleanText, "<ref.->", "") | ||
cleanText = string.gsub(cleanText, "<!%-%-.-%-%->", "") | cleanText = string.gsub(cleanText, "<!%-%-.-%-%->", "") | ||
local limit = 10 | local limit = 10 | ||
while string.find(cleanText, "{{.-}}") and limit > 0 do | while string.find(cleanText, "{{.-}}") and limit > 0 do | ||
| 第36行: | 第38行: | ||
cleanText = string.gsub(cleanText, "\n", " ") | cleanText = string.gsub(cleanText, "\n", " ") | ||
-- 3. | -- 3. 延展截断逻辑 | ||
local targetLen = 100 | local targetLen = 100 | ||
local summary = "" | local summary = "" | ||
if mw.ustring.len(cleanText) <= targetLen then | |||
summary = cleanText | summary = cleanText | ||
else | else | ||
| 第47行: | 第47行: | ||
local restText = mw.ustring.sub(cleanText, targetLen + 1) | local restText = mw.ustring.sub(cleanText, targetLen + 1) | ||
local lastOpen = 0 | local lastOpen = 0 | ||
local lastClose = 0 | local lastClose = 0 | ||
| 第74行: | 第73行: | ||
end | end | ||
-- 4. | -- 4. 无背景、维基样式的渲染 | ||
local container = mw.html.create('div') | local container = mw.html.create('div') | ||
:css({ | :css({ | ||
['margin'] = ' | ['margin'] = '15px 0', | ||
['padding'] = ' | ['padding'] = '0', | ||
[' | ['background'] = 'transparent', -- 去除背景 | ||
['display'] = 'flow-root' -- 确保包裹右侧浮动图片 | |||
['display'] = 'flow-root' | |||
}) | }) | ||
-- | -- 使用维基标准 thumb 样式,会自动处理边框和间距 | ||
if firstImage then | if firstImage then | ||
container:wikitext('[[' .. firstImage .. '|thumb|150px|right|link=' .. pageName .. ']]') | container:wikitext('[[' .. firstImage .. '|thumb|150px|right|link=' .. pageName .. ']]') | ||
end | end | ||
-- | -- 标题:维基百科标准 h2 风格 | ||
container:tag('div') | container:tag('div') | ||
:css({ | :css({ | ||
['font-size'] = '1. | ['font-size'] = '1.5em', | ||
['font-weight'] = ' | ['font-family'] = '"Linux Libertine", "Georgia", "Times", serif', | ||
['margin-bottom'] = ' | ['font-weight'] = 'normal', | ||
['border-bottom'] = '1px solid #a2a9b1', -- | ['margin-bottom'] = '0.25em', | ||
['padding-bottom'] = ' | ['border-bottom'] = '1px solid #a2a9b1', -- 维基标准下划线 | ||
['padding-bottom'] = '0' | |||
}) | }) | ||
:wikitext('[[' .. pageName .. ']]') | :wikitext('[[' .. pageName .. ']]') | ||
| 第103行: | 第101行: | ||
-- 摘要 | -- 摘要 | ||
container:tag('div') | container:tag('div') | ||
:css({ ['line-height'] = '1.6' }) | :css({ | ||
['line-height'] = '1.6', | |||
['color'] = '#202122' | |||
}) | |||
:wikitext(summary) | :wikitext(summary) | ||