Function to return markdown link for a URL
This function accepts a URL and returns a markdown link for the URL:
function Get-MarkdownLinkForUrl {
<#
.SYNOPSIS
Get the webpage, extract the title, and build a markdown link for the specified URL
#>
[CmdletBinding()]
[OutputType([String])]
param (
[Parameter(Mandatory=$True)][string]$Url
)
$DebugPreference = $PSCmdlet.GetVariableValue('DebugPreference')
$Webpage = invoke-webrequest $Url
$Webpage.Content -match "<title>(?<title>.*)</title>" | out-null
$Title = $matches['Title']
"[$Title]($Url)"
}
set-alias gmd Get-MarkdownLinkForUrl
It’s run as follows:
Get-MarkdownLinkForUrl https://www.theguardian.com/football/2012/may/19/bayern-munich-chelsea-champions-league-final
…which returns:
[Chelsea win Champions League on penalties over Bayern Munich | Champions League 2011-12 | The Guardian](https://www.theguardian.com/football/2012/may/19/bayern-munich-chelsea-champions-league-final)
which when rendered looks like this: