Skip to content

Commit

Permalink
Merge pull request #444 from MetaMask/feat/715-allow-web3-in-slug
Browse files Browse the repository at this point in the history
fix: web3 slug
  • Loading branch information
kevin-chassagne authored Oct 24, 2024
2 parents 136a2cb + 3aaf0ce commit 9160b16
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/lib/utils/news.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
const { kebabCase } = require('lodash')

/**
* Custom kebab case function that preserves "web3"
* @param {string} string
* @returns {string}
*/
function customKebabCase(string) {
// Apply lodash's kebabCase
string = kebabCase(string)

// Restore "web3"
return string.replace(/web-3/gi, 'web3')
}

/**
*
* @function
*
* @name getNewsUrl
*
* @param {Object} news
*
* @return {String} final news url
*/
let getNewsUrl = news => {
let category = 'Uncategorized'
const slug = news?.slug
? kebabCase(news.slug)
: kebabCase(news.title.toLowerCase())
? customKebabCase(news.slug)
: customKebabCase(news.title.toLowerCase())

if (news.categories && news.categories.length)
category = news.categories[0].slug
return `/news/${kebabCase(category)}/${slug}/`

return `/news/${customKebabCase(category)}/${slug}/`
}

module.exports.getNewsUrl = getNewsUrl

0 comments on commit 9160b16

Please sign in to comment.