Skip to content

Commit 73cfa2b

Browse files
jorgeucanoSanderElias
authored andcommitted
fix(create-markdown): filter non ASCII characters (#190)
1 parent 76b2505 commit 73cfa2b

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

schematics/scully/src/create-markdown/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import {
88
applyWithOverwrite,
99
getPrefix,
1010
getSrc,
11-
getFileContents,
11+
getFileContents, toAscii,
1212
} from '../utils/utils';
1313
import {RunSchematicTask} from '@angular-devkit/schematics/tasks';
1414

1515
const SCULLY_CONF_FILE = '/scully.config.js';
1616
const ANGULAR_CONF_FILE = './angular.json';
1717

1818
export default (options: Schema): Rule => {
19-
options.name = options.name || 'blog';
20-
options.slug = options.slug || 'id';
19+
options.name = toAscii(options.name) || 'blog';
20+
options.slug = toAscii(options.slug) || 'id';
2121
options.sourceDir = options.sourceDir || options.name;
2222
return chain([
2323
addPost(options, options.sourceDir),

schematics/scully/src/utils/utils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,17 @@ export const yamlToJson = (filePath: string) => {
229229
};
230230

231231
export const jsonToJaml = (metaData: {}) => yaml.safeDump(metaData);
232+
233+
234+
export const toAscii = (src: string) => {
235+
// tslint:disable-next-line:one-variable-per-declaration
236+
let ch, str, i, result = '';
237+
str = JSON.stringify(src);
238+
for (i = 1; i < str.length - 1; i++) {
239+
ch = str.charCodeAt(i);
240+
if (ch > 97) {
241+
result += str.charAt(i);
242+
}
243+
}
244+
return result;
245+
};

0 commit comments

Comments
 (0)