generify slugify method
This commit is contained in:
		
							
								
								
									
										39
									
								
								.eleventy.js
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								.eleventy.js
									
									
									
									
									
								
							@ -12,18 +12,7 @@ module.exports = function (eleventyConfig) {
 | 
				
			|||||||
  eleventyConfig.addPassthroughCopy("./src/_assets/js");
 | 
					  eleventyConfig.addPassthroughCopy("./src/_assets/js");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  eleventyConfig.addShortcode("albumtile", function (title, embedLink, coverImage) {
 | 
					  eleventyConfig.addShortcode("albumtile", function (title, embedLink, coverImage) {
 | 
				
			||||||
    // hugely overcomplicated universal slug method
 | 
					    var slug = slugify(title);
 | 
				
			||||||
    var slug = title
 | 
					 | 
				
			||||||
      .toLowerCase()
 | 
					 | 
				
			||||||
      .trim()
 | 
					 | 
				
			||||||
      // remove accents
 | 
					 | 
				
			||||||
      .normalize('NFD')
 | 
					 | 
				
			||||||
      .replace(/[\u0300-\u036f]/g, '')
 | 
					 | 
				
			||||||
      // replace invalid characters with spaces
 | 
					 | 
				
			||||||
      .replace(/[^a-z0-9\s-]/g, ' ')
 | 
					 | 
				
			||||||
      .trim()
 | 
					 | 
				
			||||||
      // replace multiple spaces or hyphens with a hyphen
 | 
					 | 
				
			||||||
      .replace(/[\s-]+/g, '-');
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    return `<div>
 | 
					    return `<div>
 | 
				
			||||||
    <a class="hide" href="${embedLink}" target="${slug}">
 | 
					    <a class="hide" href="${embedLink}" target="${slug}">
 | 
				
			||||||
@ -43,17 +32,7 @@ module.exports = function (eleventyConfig) {
 | 
				
			|||||||
    var linkString = "";
 | 
					    var linkString = "";
 | 
				
			||||||
    var videoString = "";
 | 
					    var videoString = "";
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    var slug = title
 | 
					    var slug = slugify(title);
 | 
				
			||||||
      .toLowerCase()
 | 
					 | 
				
			||||||
      .trim()
 | 
					 | 
				
			||||||
      // remove accents
 | 
					 | 
				
			||||||
      .normalize('NFD')
 | 
					 | 
				
			||||||
      .replace(/[\u0300-\u036f]/g, '')
 | 
					 | 
				
			||||||
      // replace invalid characters with spaces
 | 
					 | 
				
			||||||
      .replace(/[^a-z0-9\s-]/g, ' ')
 | 
					 | 
				
			||||||
      .trim()
 | 
					 | 
				
			||||||
      // replace multiple spaces or hyphens with a hyphen
 | 
					 | 
				
			||||||
      .replace(/[\s-]+/g, '-');
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (Array.isArray(link)) {
 | 
					    if (Array.isArray(link)) {
 | 
				
			||||||
      if (typeof link[0] === 'string') {
 | 
					      if (typeof link[0] === 'string') {
 | 
				
			||||||
@ -172,3 +151,17 @@ module.exports = function (eleventyConfig) {
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					var slugify = function (preSlug) {
 | 
				
			||||||
 | 
					  return preSlug
 | 
				
			||||||
 | 
					  .toLowerCase()
 | 
				
			||||||
 | 
					  .trim()
 | 
				
			||||||
 | 
					  // remove accents
 | 
				
			||||||
 | 
					  .normalize('NFD')
 | 
				
			||||||
 | 
					  .replace(/[\u0300-\u036f]/g, '')
 | 
				
			||||||
 | 
					  // replace invalid characters with spaces
 | 
				
			||||||
 | 
					  .replace(/[^a-z0-9\s-]/g, ' ')
 | 
				
			||||||
 | 
					  .trim()
 | 
				
			||||||
 | 
					  // replace multiple spaces or hyphens with a hyphen
 | 
				
			||||||
 | 
					  .replace(/[\s-]+/g, '-');
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user