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

Fix: Remove <title> tags from SVGs #207

Merged
merged 5 commits into from
May 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 8 additions & 39 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = function( grunt ) {
svgstore: {
withCustomTemplate:{
options: {
prefix : '', // Unused by us, but svgstore demands this variable
includeTitleElement: false,
svg: { // will add and overide the the default xmlns="http://www.w3.org/2000/svg" attribute to the resulting SVG
viewBox : '0 0 24 24',
xmlns: 'http://www.w3.org/2000/svg'
Expand Down Expand Up @@ -176,16 +176,16 @@ module.exports = function( grunt ) {

},
files: {
'svg-sprite/gridicons.svg': ['svg/*.svg']
'svg-sprite/gridicons.svg': ['svg-min/*.svg']
}
},
}
},

rename: {
moveThis: {
src: 'svg-sprite/gridicons-demo.html',
dest: 'svg-sprite/index.html'
},
}
},

copy: {
Expand Down Expand Up @@ -418,41 +418,10 @@ module.exports = function( grunt ) {
var fileContent = grunt.file.read( 'svg-min/' + svgFile );

// Add transparent rectangle to each file
fileContent = fileContent.slice( 0, fileContent.indexOf( '</title>' ) + 8 ) +
var insertAt = fileContent.indexOf( '>' ) + 1;
fileContent = fileContent.slice( 0, insertAt ) +
'<rect x="0" fill="none" width="24" height="24"/>' +
fileContent.slice( fileContent.indexOf( '</title>' ) + 8, -6 ) +
fileContent.slice( -6 );

// Save and overwrite the files in svg-min
grunt.file.write( 'svg-min/' + svgFile, fileContent );

} );

});

// Update all files in svg-min to add a title element for accessibility
grunt.registerTask( 'addtitle', 'Add title element to SVGs', function() {
var svgFiles = grunt.file.expand( { filter: 'isFile', cwd: 'svg-min/' }, [ '**/*.svg' ] );

// Add stuff
svgFiles.forEach( function( svgFile ) {

// Grab the relevant bits from the file contents
var fileContent = grunt.file.read( 'svg-min/' + svgFile );

// Grab the filename without 'gridicons-' and the .svg extension
var name = svgFile.substring( 10, svgFile.lastIndexOf( '.' ) );

// Remove hyphens and convert to Title Case
var title = name.split( '-' ).map( function( item ) {
return item.charAt( 0 ).toUpperCase() + item.slice( 1 );
} ).join( ' ' );

// Add transparent rectangle to each file
fileContent = fileContent.slice( 0, fileContent.indexOf( 'viewBox="0 0 24 24">' ) + 20 ) +
'<title>' + title + '</title>' +
fileContent.slice( fileContent.indexOf( 'viewBox="0 0 24 24">' ) + 20, -6 ) +
fileContent.slice( -6 );
fileContent.slice( insertAt );

// Save and overwrite the files in svg-min
grunt.file.write( 'svg-min/' + svgFile, fileContent );
Expand All @@ -462,6 +431,6 @@ module.exports = function( grunt ) {
});

// Default task(s).
grunt.registerTask('default', ['svgmin', 'group', 'svgstore', 'rename', 'copy', 'addtitle', 'svgphp', 'kebabToCamelCase', 'svgreact', 'babel', 'addsquare', 'clean' ]);
grunt.registerTask('default', ['svgmin', 'group', 'svgstore', 'rename', 'copy', 'svgphp', 'kebabToCamelCase', 'svgreact', 'babel', 'addsquare', 'clean' ]);

};
253 changes: 1 addition & 252 deletions docs/gridicons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"grunt-contrib-copy": "^0.6.0",
"grunt-rename": "^0.1.4",
"grunt-svgmin": "^2.0.1",
"grunt-svgstore": "^0.3.6",
"grunt-svgstore": "^1.0.0",
"handlebars": "^2.0.0",
"jit-grunt": "^0.10.0",
"load-grunt-tasks": "^3.5.2",
Expand Down
338 changes: 169 additions & 169 deletions php/gridicons.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion svg-min/gridicons-add-image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-add-outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-align-center.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-align-image-center.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-align-image-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-align-image-none.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-align-image-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-align-justify.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-align-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-align-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-arrow-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-arrow-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-arrow-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-arrow-up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-aside.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-attachment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-audio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-bell.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-block.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-bold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-book.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-bookmark-outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-bookmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion svg-min/gridicons-briefcase.svg
2 changes: 1 addition & 1 deletion svg-min/gridicons-calendar.svg
2 changes: 1 addition & 1 deletion svg-min/gridicons-camera.svg
Loading