Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the issue of missing h1 on the homepage when top_img == false, which enhanced SEO #1556

Closed
wants to merge 3 commits into from

Conversation

RoversX
Copy link

@RoversX RoversX commented Aug 30, 2024

When set index_img: false in config.yml

homepage will not display any h1

Fixed missing h1 on home page when top_img == false
support css hidden home title
add hidden-home-title css
@RoversX
Copy link
Author

RoversX commented Aug 30, 2024

Using 4.13.0

Changed:

  1. hexo-theme-butterfly/layout/includes/header/index.pug
  if top_img !== false
    - var imgSource = top_img && isImgOrUrl(top_img) ? `background-image: url('${url_for(top_img)}')` : `background: ${top_img}`
    - var bg_img = top_img ? imgSource : ''
    - var site_title = page.title || page.tag || page.category || config.title
    - var isHomeClass = is_home() ? 'full_page' : 'not-home-page'
    - is_post() ? isHomeClass = 'post-bg' : isHomeClass
  else
    - var isHomeClass = 'not-top-img'
    if is_home() // Start
      - var site_title = config.title 
      - var hideHomeTitleClass = 'hidden-home-title' // End
header#page-header(class=`${isHomeClass+isFixedClass}` style=bg_img)
  !=partial('includes/header/nav', {}, {cache: true})
  if top_img !== false
    if is_post()
      include ./post-info.pug
    else if is_home() 
      #site-info
        h1#site-title=site_title
        if theme.subtitle.enable
          - var loadSubJs = true
          #site-subtitle
            span#subtitle
        if(theme.social)
          #site_social_icons
            !=partial('includes/header/social', {}, {cache: true})
      #scroll-down
        i.fas.fa-angle-down.scroll-down-effects
    else
      #page-site-info
        h1#site-title=site_title
  else // Start
   if is_home()  
      #page-site-info  
        h1#site-title(class=hideHomeTitleClass)= site_title  // End
  1. hexo-theme-butterfly/source/css/_layout/head.styl
  #site-title
    margin: 0
    color: var(--white)
    font-size: 1.85em

    +minWidth768()
      font-size: 2.85em

    &.hidden-home-title // Start
      position: absolute
      clip: rect(1px, 1px, 1px, 1px)
      -webkit-clip-path: inset(0px 0px 99.9% 99.9%)
      clip-path: inset(0px 0px 99.9% 99.9%)
      overflow: hidden
      height: 1px
      width: 1px
      padding: 0
      border: 0 // End

@jerryc127
Copy link
Owner

所以你的目的是加一个h1标签,然后将元素隐藏?

实现这种功能应该不至于更改那么多内容吧

还有把一些主题需要的css也删了?

还有新版本已经更改的内容,非必要不要修改回旧版的

@RoversX
Copy link
Author

RoversX commented Aug 31, 2024

所以你的目的是加一个h1标签,然后将元素隐藏?

实现这种功能应该不至于更改那么多内容吧

还有把一些主题需要的css也删了?

还有新版本已经更改的内容,非必要不要修改回旧版的

感谢回复。实际修改是在原有代码的基础上添加了一个判断,当 top_img 为 false 且页面是 is_home 时,插入一个 h1 标签,同时通过 CSS 将其隐藏。除了这些,其他内容都没有变动。theme的css也没有删掉过

您提到我修改了其他内容,可能是因为我在本地使用了 4.13 的 master 分支进行修改,完成后直接替换到 dev 分支时,没注意到 dev 分支已经有了一些新的修改,造成了这个问题。

hexo-theme-butterfly/layout/includes/header/index.pug

代码修改部分大致如下:

else
   if is_home()  
      #page-site-info  
        h1#site-title(class=hideHomeTitleClass)= site_title

谢谢!

@jerryc127 jerryc127 closed this Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants