Add: parse author string

This commit is contained in:
eight 2017-10-06 15:25:37 +08:00
parent 0f6de587ec
commit b866688a87
3 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
<path d="M4,4h5v2H6v8h8v-3h2v5H4V4z M11,3h6v6l-2-2l-4,4L9,9l4-4L11,3z"></path>
</svg>

After

Width:  |  Height:  |  Size: 148 B

View File

@ -8,6 +8,11 @@ body {
box-sizing: border-box; box-sizing: border-box;
} }
img.icon {
height: 1.4em;
vertical-align: middle;
}
.container { .container {
display: flex; display: flex;
height: 100vh; height: 100vh;

View File

@ -71,7 +71,8 @@
$('.meta-description').textContent = data.description; $('.meta-description').textContent = data.description;
$('.meta-author').parentNode.style.display = data.author ? '' : 'none'; $('.meta-author').parentNode.style.display = data.author ? '' : 'none';
$('.meta-author').textContent = data.author; $('.meta-author').textContent = '';
$('.meta-author').appendChild(makeAuthor(data.author));
$('.meta-license').parentNode.style.display = data.license ? '' : 'none'; $('.meta-license').parentNode.style.display = data.license ? '' : 'none';
$('.meta-license').textContent = data.license; $('.meta-license').textContent = data.license;
@ -87,6 +88,41 @@
$('.external-link').appendChild(externalLink); $('.external-link').appendChild(externalLink);
} }
function makeAuthor(text) {
const match = text.match(/^(.+?)(?:\s+<(.+?)>)?(?:\s+\((.+?)\))$/);
if (!match) {
return document.createTextNode(text);
}
const [, name, email, url] = match;
const frag = document.createDocumentFragment();
if (email) {
frag.appendChild($element({
tag: 'a',
textContent: name,
href: `mailto:${email}`
}));
} else {
frag.appendChild($element({
tag: 'span',
textContent: name
}));
}
if (url) {
frag.appendChild($element({
tag: 'a',
href: url,
target: '_blank',
rel: 'noopener',
appendChild: $element({
tag: 'img',
className: 'icon',
src: '/install-usercss/external.svg'
})
}));
}
return frag;
}
function makeExternalLink() { function makeExternalLink() {
const urls = []; const urls = [];
if (data.homepageURL) { if (data.homepageURL) {