Interpret and create a blog publication like Twitter and Facebook automatically.
LinkHandler is an https.onCall Firebase function which receives the url of the blog published online as its variable and handles the content of the blog in an organized fashion
How the algorithm works:
- Receive URL
- Analyse the content of the url (main image, title, description, publicaiton date, domain name, etc...).
- Retrieve the last stored blog content file from firebase storage bucket.
- Decide whether to create a new blog file (which contains multiple blog information) based on specified rules.
- Update the new data back to the storage bucket.
- Magic!
There is a main file created in the storage bucket called: blogFileCounter.json
which holds a counter
of the number of blog files (files which hold blogs information). This is used to get the last file created
blogFileCounter.json
:
{
"key": 2
}
Blog files are names as blogs_xx.json
where xx
is the file number.
For example, blogs_31.json
should look something like this:
Key |
---|
10 |
Blogs[0] | Blogs[1] | ....... | Blogs[9] |
---|---|---|---|
title | title | ... | title |
description | description | ... | description |
image | image | ... | image |
source | source | ... | source |
url | url | ... | url |
date | date | ... | date |
The reasons for dividing the data into separate files are for organization and efficiency purposes. Loading or requesting data for 10 blogs on one page load is manageable. But not 120 blogs at once. This way json data handling is controlled and not flooded at once
the blogFileCounter.json
will allow us to request the latest pushed blogs on from our front end easily. A Load More
or autoload on scroll can be introduced with this data devision.
Like this:
- When first 10 blogs load from the last file, you have stored the file counter key value
Load More
calls file blogs_(file counter key
- 1).json, and so on...
By default, this algorithm creates a new file and increments the file counter every time the last file contains 10 blogs' information.
LinkHandler requires Node.js, Firebase to run.
Procedure:
$ git clone https://github.com/skhetcho/LinkHandling.git
You will get the index.ts file which you can copy paste in your firebase project Enjoy!
MIT
Open Source Software, Hell Yeah!