ESLint improvements for Profile Metadata

This commit is contained in:
kibigo! 2017-06-23 18:43:30 -07:00
parent 67adbcc60c
commit 414dfb3955
1 changed files with 11 additions and 11 deletions

View File

@ -41,27 +41,27 @@ const messages = defineMessages({
@kibi@glitch.social <3 @kibi@glitch.social <3
*/ */
const NEW_LINE = /(?:^|\r?\n|<br\s*\/?>)/g const NEW_LINE = /(?:^|\r?\n|<br\s*\/?>)/g;
const YAML_OPENER = /---/; const YAML_OPENER = /---/;
const YAML_CLOSER = /(?:---|\.\.\.)/; const YAML_CLOSER = /(?:---|\.\.\.)/;
const YAML_STRING = /(?:"(?:[^"\n]){1,32}"|'(?:[^'\n]){1,32}'|(?:[^'":\n]){1,32})/g; const YAML_STRING = /(?:"(?:[^"\n]){1,32}"|'(?:[^'\n]){1,32}'|(?:[^'":\n]){1,32})/g;
const YAML_LINE = new RegExp("\\s*" + YAML_STRING.source + "\\s*:\\s*" + YAML_STRING.source + "\\s*", "g"); const YAML_LINE = new RegExp('\\s*' + YAML_STRING.source + '\\s*:\\s*' + YAML_STRING.source + '\\s*', 'g');
const BIO_REGEX = new RegExp(NEW_LINE.source + "*" + YAML_OPENER.source + NEW_LINE.source + "+(?:" + YAML_LINE.source + NEW_LINE.source + "+){0,4}" + YAML_CLOSER.source + NEW_LINE.source + "*"); const BIO_REGEX = new RegExp(NEW_LINE.source + '*' + YAML_OPENER.source + NEW_LINE.source + '+(?:' + YAML_LINE.source + NEW_LINE.source + '+){0,4}' + YAML_CLOSER.source + NEW_LINE.source + '*');
const processBio = (data) => { const processBio = (data) => {
let props = {text: data, metadata: []}; let props = { text: data, metadata: [] };
let yaml = data.match(BIO_REGEX); let yaml = data.match(BIO_REGEX);
if (!yaml) return props; if (!yaml) return props;
else yaml = yaml[0]; else yaml = yaml[0];
let start = props.text.indexOf(yaml); let start = props.text.indexOf(yaml);
let end = start + yaml.length; let end = start + yaml.length;
props.text = props.text.substr(0, start) + props.text.substr(end); props.text = props.text.substr(0, start) + props.text.substr(end);
yaml = yaml.replace(NEW_LINE, "\n"); yaml = yaml.replace(NEW_LINE, '\n');
let metadata = (yaml ? yaml.match(YAML_LINE) : []) || []; let metadata = (yaml ? yaml.match(YAML_LINE) : []) || [];
for (let i = 0; i < metadata.length; i++) { for (let i = 0; i < metadata.length; i++) {
let result = metadata[i].match(YAML_STRING); let result = metadata[i].match(YAML_STRING);
if (result[0][0] === '"' || result[0][0] === "'") result[0] = result[0].substr(1, result[0].length - 2); if (result[0][0] === '"' || result[0][0] === '\'') result[0] = result[0].substr(1, result[0].length - 2);
if (result[1][0] === '"' || result[1][0] === "'") result[0] = result[1].substr(1, result[1].length - 2); if (result[1][0] === '"' || result[1][0] === '\'') result[0] = result[1].substr(1, result[1].length - 2);
props.metadata.push(result); props.metadata.push(result);
} }
return props; return props;
@ -184,7 +184,7 @@ export default class Header extends ImmutablePureComponent {
<span className='account__header__display-name' dangerouslySetInnerHTML={displayNameHTML} /> <span className='account__header__display-name' dangerouslySetInnerHTML={displayNameHTML} />
<span className='account__header__username'>@{account.get('acct')} {lockedIcon}</span> <span className='account__header__username'>@{account.get('acct')} {lockedIcon}</span>
<div className='account__header__content' dangerouslySetInnerHTML={{__html: emojify(text)}} /> <div className='account__header__content' dangerouslySetInnerHTML={{ __html: emojify(text) }} />
{info} {info}
{actionBtn} {actionBtn}
@ -199,11 +199,11 @@ export default class Header extends ImmutablePureComponent {
data.push( data.push(
<div <div
className='account__metadata-item' className='account__metadata-item'
title={metadata[i][0] + ":" + metadata[i][1]} title={metadata[i][0] + ':' + metadata[i][1]}
key={i} key={i}
> >
<span dangerouslySetInnerHTML={{__html: emojify(metadata[i][0])}} /> <span dangerouslySetInnerHTML={{ __html: emojify(metadata[i][0]) }} />
<strong dangerouslySetInnerHTML={{__html: emojify(metadata[i][1])}} /> <strong dangerouslySetInnerHTML={{ __html: emojify(metadata[i][1]) }} />
</div> </div>
); );
} }