Project Plan: Bookmark Filtering and Exporting Web Application
To build your bookmark filtering and exporting web application, you'll need to create a set of files that handle data processing, user interface, and interaction logic. Below is a detailed plan outlining the necessary files, their purposes, and the technologies involved.
Overview
- Technologies Used: HTML, CSS, JavaScript (both client-side and Node.js server-side scripts)
- Files to Create:
links.txt
process_links.js
data.json
index.html
styles.css
main.js
File Details
1. links.txt (Text File)
2. process_links.js (Node.js Script)
-
Language: JavaScript (Node.js)
-
Purpose: Processes links.txt to extract necessary data and saves it into data.json.
-
Functions:
- Read
links.txt file.
- Parse each URL to extract:
- Domain Name (e.g., "google" from "news.google.com")
- Top-Level Domain (TLD) (e.g., ".com" from "google.com")
- Fetch the webpage of each link to retrieve the page title.
- Handle exceptions if a page cannot be reached.
- Detect if the page title is in English or another language.
- Utilize a language detection library (e.g.,
franc or detect-language npm packages).
- Store all processed data in an array of objects.
- Write the array to
data.json.
-
Required Node.js Modules:
fs (File System) - to read and write files.
url - to parse URLs.
axios or node-fetch - to make HTTP requests.
cheerio - to parse HTML and extract titles.
- Language detection library (
franc, detect-language, etc.).
-
Usage:
node process_links.js
-
Notes:
- Running this script may take some time due to the number of bookmarks.
- Implement throttling or delays if necessary to avoid overwhelming servers.
3. data.json (JSON File)
- Language: JSON
- Purpose: Stores the processed bookmark data for use in the web application.
- Content Structure:
[
{
"url": "http://example.com",
"title": "Example Domain",
"domain": "example",
"tld": ".com",
"isEnglish": true
},
{
"url": "https://news.google.com",
"title": "Google News",
"domain": "google",
"tld": ".com",
"isEnglish": true
},
{
"url": "http://krea.ai",
"title": "Krea AI - Create with AI",
"domain": "krea",
"tld": ".ai",
"isEnglish": true
},
...
]
- Notes:
- This file is generated by
process_links.js.
- The web application will fetch and use this data to display and filter bookmarks.
4. index.html (HTML File)
5. styles.css (CSS File)
- Language: CSS
- Purpose: Provides styling for the web application.
- Styles Include:
- Layout: Define the layout for the filters section and links display section.
- Tiles:
- Style each link tile.
- Highlight non-English titles by setting the text color to blue.
- Checkboxes: Style checkboxes for selection.
- Buttons: Style the export button.
- Notes:
- Focus on functionality over aesthetics, but ensure the interface is clean and user-friendly.
- Use responsive design principles if you plan to use the app on different devices.
6. main.js (Client-Side JavaScript File)
- Language: JavaScript
- Purpose: Handles data fetching, user interactions, filtering logic, and exporting functionality.
- Functions:
- Fetch Data:
- Load
data.json using fetch() API.
- Render Tiles:
- Dynamically create and display tiles for each bookmark in
data.json.
- Each tile includes:
- Page title.
- Checkbox for selection.
- Hidden or visible indicators for domain and TLD (for debugging or extension purposes).
- Implement Filters:
- Add event listeners to filter inputs.
- Filter the displayed tiles based on:
- Domain Name: Matches the domain filter input.
- TLD: Matches the TLD filter input.
- Update the display to show only the tiles that match the filters.
- Sorting:
- Sort tiles alphabetically by page title.
- Handle titles not in English by placing an indicator (e.g., blue text).
- Export Functionality:
- Collect all selected bookmarks when the export button is clicked.
- Create a Blob of the selected URLs and prompt the user to download it as a
txt file.
- Example of creating and downloading a file:
function exportSelectedLinks(selectedLinks) {
const blob = new Blob([selectedLinks.join('\n')], { type: 'text/plain;charset=utf-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'selected_links.txt';
a.click();
URL.revokeObjectURL(url);
}
- Notes:
- Ensure cross-browser compatibility.
- Handle edge cases, such as no matches found or no links selected.
- Optimize performance since dealing with a large number of elements (8000 bookmarks).
Summary of Steps
-
Prepare Your Links: Make sure links.txt contains all your bookmarks, one per line.
-
Process the Links:
- Run
process_links.js using Node.js to generate data.json.
- Command:
node process_links.js
-
Set Up the Web Application:
- Place
index.html, styles.css, and main.js in the same directory.
- Ensure that
index.html correctly references styles.css and main.js.
-
Test the Application:
- Open
index.html in a web browser.
- Verify that all bookmarks are displayed correctly.
- Test the filters by entering domain names and TLDs.
- Select some tiles using the checkboxes.
- Click the export button and check that
selected_links.txt contains the correct URLs.
-
Deployment Considerations:
- For local use, you can open
index.html directly.
- For web deployment, host the files on a web server.
- Ensure that
data.json is accessible to the client-side script.
Additional Notes
-
Data Fetching Limitations:
- Loading local JSON files (
data.json) via fetch() may not work when opening index.html directly due to CORS restrictions.
- To avoid this issue, you may need to run a local server.
- Simple Python server:
python -m http.server 8000
- Node.js server or any other static file server.
-
Fetching Page Titles:
- Fetching page titles for 8000 bookmarks can be time-consuming.
- Consider processing the links in batches or adding a progress indicator.
- Cache the results by not rerunning
process_links.js unless links.txt changes.
-
Language Detection Accuracy:
- Automatic language detection may not be 100% accurate.
- The indication of non-English titles is a best-effort approximation.
-
Error Handling in process_links.js:
- Implement try-catch blocks to handle network errors.
- Skip URLs that cannot be processed and log them if necessary.
-
Extensibility:
- The application can be extended to include additional filters or functionalities.
- Consider modularizing your code in
main.js for easier maintenance.
By following this plan, you'll create a functional web application that allows you to filter your bookmarks based on domain and TLD, view the links with their website titles, select desired links, and export them to a text file. The combination of Node.js for data processing and client-side JavaScript for interactivity provides an efficient way to handle a large number of bookmarks while keeping the application responsive.