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

Release/4.5.0 #2391

Merged
merged 12 commits into from
May 8, 2024
Merged

Release/4.5.0 #2391

merged 12 commits into from
May 8, 2024

Conversation

tangly1024
Copy link
Owner

@tangly1024 tangly1024 commented May 8, 2024

主要改动,url的生成规则: 新增 %category% 变量,支持生成的文章路径 为
/【文章分类】/【文章slug】

目前所有支持的url变量有 %category% %year% %month% %day% %slug%


/**
 * 获取自定义URL
 * 可以根据变量生成URL
 * 支持:%category%/%year%/%month%/%day%/%slug%
 * @param {*} postProperties
 * @returns
 */
function generateCustomizeSlug(postProperties) {
  let fullPrefix = ''
  const allSlugPatterns = BLOG.POST_URL_PREFIX.split('/')
  allSlugPatterns.forEach((pattern, idx) => {
    if (pattern === '%year%' && postProperties?.publishDay) {
      const formatPostCreatedDate = new Date(postProperties?.publishDay)
      fullPrefix += formatPostCreatedDate.getUTCFullYear()
    } else if (pattern === '%month%' && postProperties?.publishDay) {
      const formatPostCreatedDate = new Date(postProperties?.publishDay)
      fullPrefix += String(formatPostCreatedDate.getUTCMonth() + 1).padStart(
        2,
        0
      )
    } else if (pattern === '%day%' && postProperties?.publishDay) {
      const formatPostCreatedDate = new Date(postProperties?.publishDay)
      fullPrefix += String(formatPostCreatedDate.getUTCDate()).padStart(2, 0)
    } else if (pattern === '%slug%') {
      fullPrefix += postProperties.slug ?? postProperties.id
    } else if (pattern === '%category%' && postProperties?.category) {
      fullPrefix += postProperties.category
    } else if (!pattern.includes('%')) {
      fullPrefix += pattern
    } else {
      return
    }
    if (idx !== allSlugPatterns.length - 1) {
      fullPrefix += '/'
    }
  })
  if (fullPrefix.startsWith('/')) {
    fullPrefix = fullPrefix.substring(1) // 去掉头部的"/"
  }
  if (fullPrefix.endsWith('/')) {
    fullPrefix = fullPrefix.substring(0, fullPrefix.length - 1) // 去掉尾部部的"/"
  }
  return `${fullPrefix}/${postProperties.slug ?? postProperties.id}`
}

其它功能做了微调,文章对象新增href成员属性,作为页面的最终跳转地址。

Copy link

vercel bot commented May 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
notion-next-home ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2024 8:50am
notion-next-seo-lesson ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2024 8:50am

Copy link

netlify bot commented May 8, 2024

Deploy Preview for beamish-semolina-0ecf31 ready!

Name Link
🔨 Latest commit 5efec54
🔍 Latest deploy log https://app.netlify.com/sites/beamish-semolina-0ecf31/deploys/663b3c4b2981df0009a5a7c7
😎 Deploy Preview https://deploy-preview-2391--beamish-semolina-0ecf31.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

Deploying notionnext with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5efec54
Status:🚫  Build failed.

View logs

? post.pageIcon
: siteConfig('IMG_LAZY_LOAD_PLACEHOLDER')
pageIcon =
post.pageIcon.indexOf('amazonaws.com') !== -1

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High

'
amazonaws.com
' can be anywhere in the URL, and arbitrary hosts may come before or after it.
@tangly1024 tangly1024 merged commit 251aa21 into main May 8, 2024
10 of 12 checks passed
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.

None yet

1 participant