Browse Source

implement parsing and display of bangs and effective names, rename img to icon, change default links, update readme

main
familyfriendlymikey 2 years ago
parent
commit
adbd1f942e
  1. 69
      app/client.imba
  2. 2
      app/config.imba
  3. 10
      app/db.imba
  4. 95
      readme.md

69
app/client.imba

@ -1,6 +1,6 @@
let p = console.log let p = console.log
import { orderBy } from 'lodash' import { orderBy, omit } from 'lodash'
import { version } from '../package.json' import { version } from '../package.json'
import db from './db' import db from './db'
import fzi from 'fzi' import fzi from 'fzi'
@ -50,12 +50,12 @@ tag app
let initial_links = [ let initial_links = [
"tutorial github.com/familyfriendlymikey/fuzzyhome" "tutorial github.com/familyfriendlymikey/fuzzyhome"
"!brave search search.brave.com/search?q=" "!brave search search.brave.com/search?q="
"!youtube search youtube.com/results?search_query=" "!youtube ~y youtube.com/results?search_query="
"photopea photopea.com" "photopea photopea.com"
"twitch twitch.tv" "twitch twitch.tv"
"messenger messenger.com" "messenger ~m messenger.com"
"instagram instagram.com" "instagram ~in instagram.com"
"localhost 3000 http://localhost:3000" "localhost:3000 ~3 http://localhost:3000"
] ]
for link in initial_links for link in initial_links
try try
@ -66,9 +66,10 @@ tag app
def validate_config def validate_config
throw _ if config.default_bang.id is null throw _ if config.default_bang.id is null
throw _ if config.default_bang.url is null throw _ if config.default_bang.url is null
throw _ if config.default_bang.img is null throw _ if config.default_bang.icon is null
throw _ if config.default_bang.name is null throw _ if config.default_bang.name is null
throw _ if config.default_bang.frequency is null throw _ if config.default_bang.frequency is null
throw _ if config.default_bang.display_name is null
def reset_config def reset_config
p "resetting config" p "resetting config"
@ -157,9 +158,17 @@ tag app
let url = split_text.pop! let url = split_text.pop!
let host let host
{ href:url, host } = parse_url url { href:url, host } = parse_url url
let img = await fetch_image_as_base_64 host let icon = await fetch_image_as_base_64 host
let name = split_text.join(" ") let name
{ name, url, frequency:0, img } if split_text[-1].startsWith "~"
name = split_text.pop!.slice(1)
let display_name = split_text.join(" ")
let is_bang = no
if display_name.startsWith "!"
is_bang = yes
display_name = display_name.slice(1)
name ||= display_name
{ name, display_name, is_bang, url, frequency:0, icon }
def handle_add def handle_add
loading = yes loading = yes
@ -177,11 +186,20 @@ tag app
await db.links.add link await db.links.add link
await reload_db! await reload_db!
imba.commit! imba.commit!
p omit(link, "icon")
return link return link
def construct_link_text link
let link_text = ""
link_text += "!" if link.is_bang
link_text += link.display_name
link_text += " ~{link.name}" if link.name isnt link.display_name
link_text += " {link.url}"
link_text
def handle_edit link def handle_edit link
def edit_link def edit_link
let input = window.prompt "Enter the new link name and url:", "{link.name} {link.url}" let input = window.prompt "Enter the new link name and url:", construct_link_text(link)
return if input is null return if input is null
try try
await update_link link, input await update_link link, input
@ -198,11 +216,16 @@ tag app
throw "link id not found" if result is 0 throw "link id not found" if result is 0
await reload_db! await reload_db!
imba.commit! imba.commit!
p omit(old_link, "icon")
p omit(new_link, "icon")
return new_link return new_link
def handle_click_link link def handle_click_link link
await increment_link_frequency link if link.is_bang
window.location.href = link.url state.query = ''
bang = link
else
navigate link
def handle_bang def handle_bang
await increment_link_frequency active_bang await increment_link_frequency active_bang
@ -219,7 +242,7 @@ tag app
if bang or state.scored_links.length < 1 if bang or state.scored_links.length < 1
return handle_bang! return handle_bang!
let link = state.scored_links[selection_index] let link = state.scored_links[selection_index]
if link.name.startsWith '!' if link.is_bang
state.query = '' state.query = ''
bang = link bang = link
else else
@ -236,7 +259,7 @@ tag app
def handle_delete link def handle_delete link
def delete_link def delete_link
return unless window.confirm "Do you really want to delete {link..name}?" return unless window.confirm "Do you really want to delete {link..display_name}?"
try try
await db.links.delete(link.id) await db.links.delete(link.id)
catch e catch e
@ -374,10 +397,14 @@ tag app
css .link-icon css .link-icon
w:20px h:20px mr:10px rd:3px w:20px h:20px mr:10px rd:3px
css .name css .display-name
tt:capitalize fs:20px tt:capitalize fs:20px
overflow-wrap:anywhere overflow-wrap:anywhere
css .name
d:flex ja:center
c:gray4/45 ml:10px fs:14px
css .bang-text css .bang-text
tt:none word-break:break-all tt:none word-break:break-all
@ -461,8 +488,8 @@ tag app
@click=handle_click_bang @click=handle_click_bang
> >
<.link-left> <.link-left>
<img.link-icon src=active_bang.img> <img.link-icon src=active_bang.icon>
<.name.bang-text> encoded_bang_query <.display-name.bang-text> encoded_bang_query
<.link-right[jc:flex-end]> <.link-right[jc:flex-end]>
<.frequency> active_bang.frequency <.frequency> active_bang.frequency
else else
@ -474,8 +501,12 @@ tag app
.selected=(index == selection_index) .selected=(index == selection_index)
> >
<.link-left> <.link-left>
<img.link-icon src=link.img> <img.link-icon src=link.icon>
<.name> link.name <.display-name> link.display_name
if link.display_name isnt link.name
<.name> "{link.is_bang ? "!" : "~"}{link.name}"
elif link.is_bang
<.name> "!"
<.link-right> <.link-right>
<.link-buttons> <.link-buttons>
<.link-button[fs:12px]@click.prevent.stop=handle_click_edit(link)> "✎" <.link-button[fs:12px]@click.prevent.stop=handle_click_edit(link)> "✎"

2
app/config.imba

File diff suppressed because one or more lines are too long

10
app/db.imba

@ -30,4 +30,14 @@ db.version(3).stores({
try try
link.url = parse_url(link.url).href link.url = parse_url(link.url).href
db.version(4).stores({
links: "++id,display_name,name,is_bang,url,frequency,icon"
}).upgrade! do |trans|
p "upgrading to fuzzyhome db version 4"
trans.links.toCollection!.modify! do |link|
link.display_name = link.name
link.is_bang = no
link.icon = link.img
delete link.img
export default db export default db

95
readme.md

@ -40,32 +40,70 @@ Navigate to the currently selected search result by pressing `return`.
You can also click on a link to navigate to it. You can also click on a link to navigate to it.
You can also press the up or down arrow keys to move your selection up and down. You can also press the up or down arrow keys to move your selection up and down.
### Move Selection
You can move your selection up and down with the arrow keys.
### Search ### Search
If there are no matching links, a search will be performed with your query. If there are no matching links, a search will be performed with your query.
### Quick Search
If you paste while the input is empty, fuzzyhome will immediately make a search with your pasted query.
### Bangs ### Bangs
You can easily append queries to arbitrary links, and as such use them in a similar manner as the "bang" feature from some search engines. There may be some websites you've created links for, such as amazon, where you almost always search for something.
Just get the query link for a website and create a link with that url. For example: This means you have to go to that website, click the search bar, and type in your query.
With fuzzyhome you can cut out the slow parts by prefixing your link name with `!` to create a "bank link":
```
!amazon amazon.com/s?k=
``` ```
y https://www.youtube.com/results?search_query= Notice the `/s?k=` at the end,
you'll likewise have to find the proper URL for your new bang link.
Typing instructions for that would be too verbose, so please see the video tutorial (coming soon).
When you click on or press return on a selected bang link,
instead of navigating directly to that link,
you'll be able to enter a search query for that link.
Pressing enter again will bring you to the link with your encoded search query appended to it.
### Effective Names
After using fuzzyhome enough, you may come to realize
that there are some links you'd prefer be "hardcoded"
with certain names so to speak.
For example, perhaps you visit `instagram` extremely often
but also have a link named `indeed` which gets sorted above
`instagram` when you type `in` even though you visit it much less often.
You could change the `instagram` link's name to `in`,
but now it looks bad.
To solve this, fuzzyhome allows you to add an "effective name"
to a link:
``` ```
This will create a link named `y`. instagram ~in instagram.com
Now all you have to do is press `tab` when the `y` link is selected. ```
In practice you'll just type `y<tab>`. To add an effective name to a link,
This will allow you to start typing a query which will be appended onto the url of that link. simply add the name prefixed with a tilde right before the URL.
To navigate to the link, just press `return` or click the link.
To cancel, just press `tab` again. This also works for bang links.
Let's say we wanted `a` to correspond to `!amazon`:
```
!amazon ~a amazon.com/s?k=
```
Now when you type `in` or `a`,
you can have confidence that your
intended link will be given priority every time.
Mind you, typing `am` will no longer show `amazon` in the results,
because that's just the display name for the link.
The actual name is `a`.
This might seem confusing but once you
get the hang of it won't matter to you at all.
### Delete ### Delete
You can delete notes by clicking the purple `x` on the currently selected link. You can delete notes by clicking the purple `x` on the currently selected link.
You can also use the hotkey `shift+backspace` to delete the currently selected link. You can also use the hotkey `shift+backspace` to delete the currently selected link.
### Edit
You can edit notes by clicking the edit icon.
### Move Selection
You can move your selection up and down with the arrow keys.
### Quick Search
If you paste while the input is empty, fuzzyhome will immediately make a search with your pasted query.
### Customize Search Engine ### Customize Search Engine
The default search engine is Google Search, however you can customize it by clicking the three dots to go to settings, The default search engine is Google Search, however you can customize it by clicking the three dots to go to settings,
clicking `config`, and pasting in your search engine url, such as `https://search.brave.com/search?q=`. clicking `config`, and pasting in your search engine url, such as `https://search.brave.com/search?q=`.
@ -94,26 +132,13 @@ Shift + Backspace | Delete currently selected link.
## FAQ ## FAQ
### The Link I Want Is Showing Up Last ### The Link I Want Is Showing Up Last
TLDR either rename the desired link to something shorter or the undesired link to something longer. Change the effective name of the link.
Let's say you've been typing `in` for `instagram`, but recently added `indeed` as a link,
Fuzzyhome doesn't use an algorithm that attempts to be intelligent about which links it ranks first because and `indeed` keeps showing up first.
having a more predictable behavior lets you work faster since you know it will do the same thing every single time. Simply change the effective name of the `instagram` link to `in`:
```
The search results are first filtered on character order. instagram ~in instagram.com
If the characters of a given link name are not in the same order as the query, that link will be excluded from the results. ```
So if I have a link named `messenger` and I type `mgs`,
`messenger` will be excluded from the results because the `g` does not come before the `s`.
The fuzzy search [algorithm](https://github.com/jhawthorn/fzy/blob/master/ALGORITHM.md)
prioritizes shorter strings and strings whose words begin with the letters of the query.
With those factors in mind, if you encounter a situation where a certain link you access less often is showing up in search results on top of
a link you access much more often, such as `mpv` showing up on top of a desired link `messenger`,
either lengthen `mpv`'s name to something like `_mpv`, or shorten `messenger`'s name to something like `m`.
With either of these solutions, typing `m` will always result in the desired link showing up first.
That will be the behavior every single time, regardless of which link you accessed more recently,
what time of day it is, or some other random variable.
### A Link Is Blocking My Search ### A Link Is Blocking My Search
This happens very rarely if at all. Just throw some spaces at the end of your query. This happens very rarely if at all. Just throw some spaces at the end of your query.

Loading…
Cancel
Save