Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
Improve entry domain processing
Browse files Browse the repository at this point in the history
  • Loading branch information
perry-mitchell committed Aug 30, 2020
1 parent a6798ef commit f2176a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/vault/Entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@ import React, { useContext, useState, useRef, useEffect } from 'react';
import styled, { css } from 'styled-components';
import PropTypes from 'prop-types';
import { Colors, Text, Classes, Menu, MenuItem, ContextMenu, MenuDivider } from '@blueprintjs/core';
import extractDomain from 'extract-domain';
import { DEFAULT_ENTRY_TYPE, EntryType } from 'buttercup/web';
import {
DEFAULT_ENTRY_TYPE,
EntryType,
EntryURLType,
fieldsToProperties,
getEntryURLs
} from 'buttercup/web';
import { EntryFacade } from './props';
import { getFacadeField, getThemeProp } from '../../utils';
import SiteIcon from './SiteIcon';
import { useGroups } from './hooks/vault';
import { VaultContext } from './Vault';
import { extractDomain } from './utils/domain';

function getEntryDomain(entry) {
const url = getFacadeField(entry, 'url');
const properties = fieldsToProperties(entry.fields);
const [url] = [
...getEntryURLs(properties, EntryURLType.Icon),
...getEntryURLs(properties, EntryURLType.Any)
];
return url ? extractDomain(url) : null;
}

Expand Down
7 changes: 7 additions & 0 deletions src/components/vault/utils/domain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function extractDomain(str) {
const domainMatch = str.match(/^https?:\/\/([^\/]+)/i);
if (!domainMatch) return str;
const [, domainPortion] = domainMatch;
const [domain] = domainPortion.split(':');
return domain;
}

0 comments on commit f2176a6

Please sign in to comment.