1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980(*
* Copyright (c) 2014, OCaml.org project
* Copyright (c) 2015 KC Sivaramakrishnan <sk826@cl.cam.ac.uk>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)(** This module determines an image to be used as preview of a website.
It does this by following the same logic Google+ and other websites use, and
described in this article:
https://www.raymondcamden.com/2011/07/26/How-are-Facebook-and-Google-creating-link-previews *)letog_imagehtml=letopenSoupinletsoup=parsehtmlintrysoup$"meta[property=og:image]"|>R.attribute"content"|>Option.somewithFailure_->Noneletimage_srchtml=letopenSoupinletsoup=parsehtmlintrysoup$"link[rel=\"image_src\"]"|>R.attribute"href"|>Option.somewithFailure_->Nonelettwitter_imagehtml=letopenSoupinletsoup=parsehtmlintrysoup$"meta[name=\"twitter:image\"]"|>R.attribute"content"|>Option.somewithFailure_->Noneletog_descriptionhtml=letopenSoupinletsoup=parsehtmlintrysoup$"meta[property=og:description]"|>R.attribute"content"|>Option.somewithFailure_->Noneletdescriptionhtml=letopenSoupinletsoup=parsehtmlintrysoup$"meta[property=description]"|>R.attribute"content"|>Option.somewithFailure_->Noneletpreview_imagehtml=letpreview_image=matchog_imagehtmlwith|None->(matchimage_srchtmlwith|None->twitter_imagehtml|Somex->Somex)|Somex->SomexinmatchOption.mapString.trimpreview_imagewith|Some""->None|Somex->Somex|None->Noneletdescriptionhtml=letpreview_image=matchog_descriptionhtmlwithNone->descriptionhtml|Somex->SomexinmatchOption.mapString.trimpreview_imagewith|Some""->None|Somex->Somex|None->None