Skip to content

Instantly share code, notes, and snippets.

@michel47
Last active April 1, 2021 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michel47/abc6e9727ad06fd5c2cc4855868bddf7 to your computer and use it in GitHub Desktop.
Save michel47/abc6e9727ad06fd5c2cc4855868bddf7 to your computer and use it in GitHub Desktop.
a tiny code to fetch your IPFS peerid and give you an url to your published name space (IPNS)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>get your IPFS PeerID</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
</head>
<body>
<header id="title-block-header">
<h1 class="title">get your IPFS PeerID</h1>
</header>
<h3 id="a-web-page-with-your-ipfs-peerid">a web page with your IPFS’ peerid</h3>
<p>This gist tells you what is your peerid run it live on <a href="https://bl.ocks.org/michel47/raw/abc6e9727ad06fd5c2cc4855868bddf7">bl.ocks</a></p>
<script src="https://gist.github.com/michel47/abc6e9727ad06fd5c2cc4855868bddf7.js?file=_peerid.html"></script>
<p>note: this file is compiled w/ <code>panpandoc</code></p>
</body>
</html>
<!DOCTYPE html><meta charset="utf8"><script>
if (location.protocol != 'https:' && ! location.hostname.match('localhost') && ! location.hostname.match('127\.') ) {
console.log('! https -> redirect to https://...')
location.href = 'https://'+location.host+location.pathname
}
const gw_url='http://127.0.0.1:8080'
const api_url='http://127.0.0.1:5001/api/v0/'
fetch(api_url +'id',{ method: 'POST', mode: 'cors' }).
then( resp => resp.json() ).
then( json => {
console.log('json:',json);
if (typeof(json.ID) != 'undefined') {
let peerid = json.ID;
let content = `<p>Your PeerID is <a href="${gw_url}/ipns/${peerid}/">${peerid}</a></p>`
document.write(content)
} else {
document.write('you are anonymous (no IPFS node detected)');
}
}).
catch(console.warn)
</script>
#
sh panpandoc README.md
sh panpandoc index.md
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>getting your IPFS peerid</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
</head>
<body>
<header id="title-block-header">
<h1 class="title">getting your IPFS peerid</h1>
</header>
<p>to run this page “live” click the <a href="http://bl.ocks.org//raw/abc6e9727ad06fd5c2cc4855868bddf7">Open</a> link below …</p>
<script>
const url='https://gist.githubusercontent.com/michel47/abc6e9727ad06fd5c2cc4855868bddf7/raw/_peerid.html'
fetch(url,{ method: 'GET' }).then( resp => resp.text() ).
then( html => { document.write(html.replace('<!DOCTYPE html>','')); return html; }).
catch(document.write('click the Open link below'))
</script>
</body>
</html>
title gist gistuser
getting your IPFS peerid
abc6e9727ad06fd5c2cc4855868bddf7
michel47

to run this page "live" click the Open link below ...

<script> const url='https://gist.githubusercontent.com/$gistuser$/$gist$/raw/_peerid.html' fetch(url,{ method: 'GET' }).then( resp => resp.text() ). then( html => { document.write(html.replace('','')); return html; }). catch(document.write('click the Open link below')) </script>
#
# problem:
# using $variable$ within a markdown file and have pandoc evaluate them using the frontmatter
# solution:
# run pandoc twice using the file itself as template
intent="script to have frontmatter variables evaluated using pandoc"
md=$1
if [ "o$2" != 'o' ]; then
out=$2
else
out=${md%.*}.html
fi
pandoc --template=$md $md | pandoc -s -o $out
exit $?
true; # $source: /my/shell/scripts/panpandoc $
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment