Use string() in XPath to avoid further sed-e-s and just extract the 1st og:imag… - plumb - Open certain URL patterns with an ad-hoc opener (plumber)
(HTM) hg clone https://bitbucket.org/iamleot/plumb
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) changeset e89f98c6d54347754d8d8abbf4084850717658d7
(DIR) parent d86a99e60c70cae3df952dbacb69305d60ad77e5
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Tue, 14 Aug 2018 02:15:13
Use string() in XPath to avoid further sed-e-s and just extract the 1st og:image.
Diffstat:
openers/ogimage | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
---
diff -r d86a99e60c70 -r e89f98c6d543 openers/ogimage
--- a/openers/ogimage Mon Aug 06 23:44:35 2018 +0200
+++ b/openers/ogimage Tue Aug 14 02:15:13 2018 +0200
@@ -2,7 +2,7 @@
for u in "$@"; do
imgurl=$(curl -s -L "$u" |
- xmllint --html --xpath '//meta[@property="og:image"]/@content' - 2>/dev/null |
- sed -e 's/^ content="//' -e 's/"$//' -e 's/\?.*$//' -e 's/:large$//' )
+ xmllint --html --xpath 'string(//meta[@property="og:image"][1]/@content)' - 2>/dev/null |
+ sed -e 's/\?.*$//' -e 's/:large$//' )
plumb "${imgurl}"
done