打开/关闭菜单
60
73
29
1.1K
武外梗百科
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

Module:PageSummary:修订间差异

武外梗百科 爱国好学自强图新的百科全书
无编辑摘要
无编辑摘要
第8行: 第8行:
     local content = title:getContent()
     local content = title:getContent()


     -- 1. 提取第一张图(用于单独显示)
     -- 1. 提取第一张图(用于单独在右侧显示)
    -- 匹配 [[File:名称...]]
     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
     -- A. 移除所有图片链接,防止摘要中出现多余图片或图片残留的链接文本
   
     -- 核心:彻底去除摘要文本中所有的图片标记
    -- 使用更严谨的匹配:从 [[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, "%[%[图像:.-%]%]", "")
      
      
     -- B. 移除模板、注释、引用
     -- 移除其余干扰项
     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 = ""
     local fullLen = mw.ustring.len(cleanText)
     if mw.ustring.len(cleanText) <= targetLen then
 
    if fullLen <= 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. 无背景、维基样式的渲染
    -- 使用 display: flow-root 确保容器包裹住浮动的缩略图
     local container = mw.html.create('div')
     local container = mw.html.create('div')
         :css({
         :css({
             ['margin'] = '10px 0',
             ['margin'] = '15px 0',
             ['padding'] = '10px',
             ['padding'] = '0',
             ['border'] = '1px solid #a2a9b1',
             ['background'] = 'transparent', -- 去除背景
            ['background-color'] = '#f8f9fa',
             ['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.2em',
             ['font-size'] = '1.5em',
             ['font-weight'] = 'bold',
            ['font-family'] = '"Linux Libertine", "Georgia", "Times", serif',
             ['margin-bottom'] = '5px',
             ['font-weight'] = 'normal',
             ['border-bottom'] = '1px solid #a2a9b1', -- 维基标题下划线
             ['margin-bottom'] = '0.25em',
             ['padding-bottom'] = '2px'
             ['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)