Added url parser to support wider range of addresses
This commit is contained in:
parent
5968663be4
commit
a5504e6e80
7 changed files with 63 additions and 24 deletions
13
README.md
13
README.md
|
@ -60,3 +60,16 @@ docker run -p 5005:5005 -v <host_dir>:/app/data flame
|
||||||
- Customize your page by choosing from 12 color themes
|
- Customize your page by choosing from 12 color themes
|
||||||
|
|
||||||
![Homescreen screenshot](./github/_themes.png)
|
![Homescreen screenshot](./github/_themes.png)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
### Supported links for applications and bookmarks
|
||||||
|
#### Rules
|
||||||
|
- URL starts with `http://`
|
||||||
|
- Format: `http://www.domain.com`, `http://domain.com`
|
||||||
|
- Redirect: `{dest}`
|
||||||
|
- URL starts with `https://`
|
||||||
|
- Format: `https://www.domain.com`, `https://domain.com`
|
||||||
|
- Redirect: `https://{dest}`
|
||||||
|
- URL without protocol
|
||||||
|
- Format: `www.domain.com`, `domain.com`, `sub.domain.com`, `local`, `ip`, `ip:port`
|
||||||
|
- Redirect: `http://{dest}`
|
|
@ -11,7 +11,6 @@ import Home from './components/Home/Home';
|
||||||
import Apps from './components/Apps/Apps';
|
import Apps from './components/Apps/Apps';
|
||||||
import Settings from './components/Settings/Settings';
|
import Settings from './components/Settings/Settings';
|
||||||
import Bookmarks from './components/Bookmarks/Bookmarks';
|
import Bookmarks from './components/Bookmarks/Bookmarks';
|
||||||
|
|
||||||
import NotificationCenter from './components/NotificationCenter/NotificationCenter';
|
import NotificationCenter from './components/NotificationCenter/NotificationCenter';
|
||||||
|
|
||||||
if (localStorage.theme) {
|
if (localStorage.theme) {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
|
|
||||||
import classes from './AppCard.module.css';
|
import classes from './AppCard.module.css';
|
||||||
import Icon from '../../UI/Icons/Icon/Icon';
|
import Icon from '../../UI/Icons/Icon/Icon';
|
||||||
import { iconParser } from '../../../utility/iconParser';
|
import { iconParser, urlParser } from '../../../utility';
|
||||||
|
|
||||||
import { App } from '../../../interfaces';
|
import { App } from '../../../interfaces';
|
||||||
|
|
||||||
|
@ -12,18 +10,16 @@ interface ComponentProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
const AppCard = (props: ComponentProps): JSX.Element => {
|
const AppCard = (props: ComponentProps): JSX.Element => {
|
||||||
const redirectHandler = (url: string): void => {
|
const [displayUrl, redirectUrl] = urlParser(props.app.url);
|
||||||
window.open(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a href={`http://${props.app.url}`} target='_blank' className={classes.AppCard}>
|
<a href={redirectUrl} target='_blank' className={classes.AppCard}>
|
||||||
<div className={classes.AppCardIcon}>
|
<div className={classes.AppCardIcon}>
|
||||||
<Icon icon={iconParser(props.app.icon)} />
|
<Icon icon={iconParser(props.app.icon)} />
|
||||||
</div>
|
</div>
|
||||||
<div className={classes.AppCardDetails}>
|
<div className={classes.AppCardDetails}>
|
||||||
<h5>{props.app.name}</h5>
|
<h5>{props.app.name}</h5>
|
||||||
<span>{props.app.url}</span>
|
<span>{displayUrl}</span>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Bookmark, Category } from '../../../interfaces';
|
||||||
import classes from './BookmarkCard.module.css';
|
import classes from './BookmarkCard.module.css';
|
||||||
|
|
||||||
import Icon from '../../UI/Icons/Icon/Icon';
|
import Icon from '../../UI/Icons/Icon/Icon';
|
||||||
import { iconParser } from '../../../utility/iconParser';
|
import { iconParser, urlParser } from '../../../utility';
|
||||||
|
|
||||||
interface ComponentProps {
|
interface ComponentProps {
|
||||||
category: Category;
|
category: Category;
|
||||||
|
@ -13,19 +13,23 @@ const BookmarkCard = (props: ComponentProps): JSX.Element => {
|
||||||
<div className={classes.BookmarkCard}>
|
<div className={classes.BookmarkCard}>
|
||||||
<h3>{props.category.name}</h3>
|
<h3>{props.category.name}</h3>
|
||||||
<div className={classes.Bookmarks}>
|
<div className={classes.Bookmarks}>
|
||||||
{props.category.bookmarks.map((bookmark: Bookmark) => (
|
{props.category.bookmarks.map((bookmark: Bookmark) => {
|
||||||
<a
|
const [displayUrl, redirectUrl] = urlParser(bookmark.url);
|
||||||
href={`http://${bookmark.url}`}
|
|
||||||
target='_blank'
|
return (
|
||||||
key={`bookmark-${bookmark.id}`}>
|
<a
|
||||||
{bookmark.icon && (
|
href={redirectUrl}
|
||||||
<div className={classes.BookmarkIcon}>
|
target='_blank'
|
||||||
<Icon icon={iconParser(bookmark.icon)} />
|
key={`bookmark-${bookmark.id}`}>
|
||||||
</div>
|
{bookmark.icon && (
|
||||||
)}
|
<div className={classes.BookmarkIcon}>
|
||||||
{bookmark.name}
|
<Icon icon={iconParser(bookmark.icon)} />
|
||||||
</a>
|
</div>
|
||||||
))}
|
)}
|
||||||
|
{bookmark.name}
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
/**
|
||||||
|
* Parse Material Desgin icon name to be used with mdi/js
|
||||||
|
* @param mdiName Dash separated icon name from MDI, e.g. alert-box-outline
|
||||||
|
* @returns Parsed icon name to be used with mdi/js, e.g mdiAlertBoxOutline
|
||||||
|
*/
|
||||||
export const iconParser = (mdiName: string): string => {
|
export const iconParser = (mdiName: string): string => {
|
||||||
let parsedName = mdiName
|
let parsedName = mdiName
|
||||||
.split('-')
|
.split('-')
|
||||||
|
|
2
client/src/utility/index.ts
Normal file
2
client/src/utility/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
export * from './iconParser';
|
||||||
|
export * from './urlParser';
|
20
client/src/utility/urlParser.ts
Normal file
20
client/src/utility/urlParser.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
export const urlParser = (url: string): string[] => {
|
||||||
|
let parsedUrl: string;
|
||||||
|
let displayUrl: string;
|
||||||
|
|
||||||
|
if (/https?:\/\//.test(url)) {
|
||||||
|
// Url starts with http[s]:// -> leave it as it is
|
||||||
|
parsedUrl = url;
|
||||||
|
} else {
|
||||||
|
// No protocol -> apply http:// prefix
|
||||||
|
parsedUrl = `http://${url}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create simplified url to display as text
|
||||||
|
displayUrl = url
|
||||||
|
.replace(/https?:\/\//, '')
|
||||||
|
.replace('www.', '')
|
||||||
|
.replace(/\/$/, '');
|
||||||
|
|
||||||
|
return [displayUrl, parsedUrl]
|
||||||
|
}
|
Loading…
Reference in a new issue