Kovah / LinkAce

LinkAce is a self-hosted archive to collect links of your favorite websites.
https://www.linkace.org
GNU General Public License v3.0
2.63k stars 164 forks source link

Small enhancement to import Google Bookmarks - with some code draft #316

Open krylm opened 3 years ago

krylm commented 3 years ago

Thank you for LInkAce. I was looking for replacement for Google Bookmarks manager and LinkAce is right option for me.

I have almost 10k links stored in Google Bookmarks and every link has 4 or more tags. This results in 9 MB file GoogleBookmarks.html to import. Current setup imports all links, but only with one tag. Every other tags are ignored because of duplicit in other section with different name.

I've created short preprocessing function to aggregate tags to according links before storing to database. And everything is correctly imported to database.

I don't have skill enough (and don't know Laravel fw at all) to create pull request to modify behaviour or make some other option to import GoogleBookmarks in aggregated way.

But I can share code snippet, which worked for me, to implement it in codebase if you want. https://github.com/Kovah/LinkAce/blob/main/app/Actions/ImportHtmlBookmarks.php#L42

function preprocess_bookmarks($data) {
    $output = [];
    foreach ($data as $k => $v) {
        $found = False;
        foreach ($output as $idx => $item) {
            if ( $item['uri'] == $v['uri'] ) {
                $found = $idx;
                break;
            }
        }

       if ($found !== False) {
            $output[$found]['tags'][] = $v['tags'];
        } else {
            $add_item = $v;
            $add_item['tags'] = array($v['tags']);
            $add_item['title'] = addslashes( html_entity_decode($v['title'], ENT_QUOTES | ENT_XML1, '                                                      UTF-8') );
            $add_item['note'] = addslashes( html_entity_decode($v['note'], ENT_QUOTES | ENT_XML1, 'UT                                                      F-8') );
            $output[] = $add_item;
        }
    }

    return $output;
}

// preprocessing

$links = preprocess_bookmarks($links);

And modify exploding tags variable to don't explode it at all. https://github.com/Kovah/LinkAce/blob/main/app/Actions/ImportHtmlBookmarks.php#L72

// $tags = explode(' ', $link['tags']);
$tags = $link['tags'];

With this small modification I was able to import complete file from Google Bookmarks and migrade to LinkAce.

Kovah commented 3 years ago

Hi! Thanks for the valuable feedback. I got other reports of imports from Chrome being broken. I will take a look when I have the time.

Kovah commented 2 years ago

Also requested by @Fivefold

Additional info:

This seems to be related to the used shaarli bookmark parser (see sebsauvage/Shaarli#22).