当前位置:网站首页>Card link
Card link
2022-07-25 20:27:00 【Let let】
original text : https://blog.imlete.cn/article/CardLink.html
Sometimes I often see Zhihu's articles , Or the link in the question is card
Compare card links with ordinary links , Card links are not only beautiful , Also show more information , Such as : title 、 picture 、 Website, etc
Open source address : https://github.com/Lete114/CardLink
The effect is as follows 
Realization principle
- Request target link HTML
- Get the results , Use
new DOMParser()Parsing the request result HTML Content , And use dom API Analyze and obtain information ( If you are good, you can use regular expression matching ) - Edit card linked HTML as well as CSS style
- Insert the parsed information into the previously edited HTML In the template , And render to the current page
Potential problems
- How to solve the cross domain problem of front-end requests
- How to get the icon of the website (icon or cover)
- If I get it (img or link) Labeled (src or href) How to solve the relative path
Such as : (/img/xxx.png) (…/img/xxx.png) (./img/xxx.png) - If I get it img Labeled src by Loading Of base64 picture , The actual real picture address is data-src, How to solve
solve the problem
Cross-domain request
- Set up a proxy server , Pass the target link to the proxy server , Let the proxy server request HTML Text and return
Warehouse address : CardLink-Server - Use online free cross domain proxy
( The former is a cross domain request service built by bloggers , The latter is a free cross domain request service found online )https://cardlink-server.deta.dev/?url=https://api.allorigins.win/raw?url=
Get the site icon
Get the target link HTML After parsing the text, get
body Next first img label —> Website icon
Solve the absolute path
Generally, we get dom After the element , Such as img label , In most cases, it is used directly .src obtain
This will lead to a very verification problem ,.src What you get is document.baseURI + img Labeled src
So you have to pass .getAttribute('src') obtain , Finally, use the target link + .getAttribute('src') that will do
The solution is Loading The problem of
If you get Loading base64 Give up the acquisition directly , Instead, get the website directly icon , If the site doesn't have icon Is displayed svg Small earth drawn
Small earth effect
边栏推荐
- [paper reading] unpaired image to image translation using cycle consistent advantageous networks
- 笔记——记录一个CannotFindDataSourceException: dynamic-datasource can not find primary datasource问题解决
- CarSim仿真快速入门(十六)—CarSim传感器仿真之ADAS Sensor Objects (2)
- 参与开源社区还有证书拿?
- [today in history] July 5: the mother of Google was born; Two Turing Award pioneers born on the same day
- Difference Between Accuracy and Precision
- 移动web布局方法
- 10.< tag-动态规划和子序列, 子数组>lt.53. 最大子数组和 + lt.392. 判断子序列 dbc
- 【TensorRT】trtexec工具转engine
- Docker builds redis cluster
猜你喜欢

【高等数学】【1】函数、极限、连续
![[cloud native | learn kubernetes from scratch] VIII. Namespace resource quotas and labels](/img/7e/2bdead512ba5bf5ccd0830b0f9b0f2.png)
[cloud native | learn kubernetes from scratch] VIII. Namespace resource quotas and labels
![[today in history] July 13: the father of database passed away; Apple buys cups code; IBM chip Alliance](/img/2d/c23a367c9e8e2806ffd5384de273d2.png)
[today in history] July 13: the father of database passed away; Apple buys cups code; IBM chip Alliance
![[cloud native] use of Nacos taskmanager task management](/img/af/f1c5359e7dbcf51f02fa32839539b2.png)
[cloud native] use of Nacos taskmanager task management

Key network protocols in tcp/ip four layer model

Technology cloud report: what is the difference between zero trust and SASE? The answer is not really important
![[today in history] July 3: ergonomic standards act; The birth of pioneers in the field of consumer electronics; Ubisoft releases uplay](/img/18/b06e2e5a2f76dc2da1c2374b8424b3.png)
[today in history] July 3: ergonomic standards act; The birth of pioneers in the field of consumer electronics; Ubisoft releases uplay

"Share" devaxpress asp Net v22.1 latest version system environment configuration requirements
![[today in history] July 19: the father of IMAP agreement was born; Project kotlin made a public appearance; New breakthroughs in CT imaging](/img/e9/5751dc435cfbbefc22d84fd9ebbaea.png)
[today in history] July 19: the father of IMAP agreement was born; Project kotlin made a public appearance; New breakthroughs in CT imaging
![PMP adopts the latest exam outline, here is [agile project management]](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
PMP adopts the latest exam outline, here is [agile project management]
随机推荐
redis源码 -ziplist
Configure and install cocos2dx development environment under Tongxin UOS
Recommended system topic | Minet: cross domain CTR prediction
飞行器pid控制(旋翼飞控)
Prescan quick start to master Lesson 19: prescan actuator configuration, track synchronization and non configuration of multiple tracks
Rainbow plug-in extension: monitor MySQL based on MySQL exporter
Do you still have certificates to participate in the open source community?
Increase swap space
Stock software development
4、Nacos 配置中心源码解析之 服务端启动
增加 swap 空间
Kubernetes进阶部分学习笔记
Network RTK UAV test [easy to understand]
移动web布局方法
当AI邂逅生命健康,华为云为他们搭建三座桥
Technology cloud report: more than zero trust, the wild hope of Parra's "Digital Security Cloud strategy"
各厂商网络虚拟化的优势
[today in history] July 13: the father of database passed away; Apple buys cups code; IBM chip Alliance
参与开源社区还有证书拿?
wallys//IPQ5018/IPQ6010/PD-60 802.3AT Input Output 10/100/1000M