Closes #98 and other minor fixes
This commit is contained in:
parent
d6c7202f31
commit
c4ebf418ce
7 changed files with 56 additions and 16 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
|
||||
|
||||
// P A C K A G E S
|
||||
// V A R I A B L E S
|
||||
|
||||
const regexForIds = /\(#.*\)/g;
|
||||
const regexForTextBeforeLink = /^.*(?=\()/g;
|
||||
|
@ -54,23 +54,23 @@ function superscript(state, silent) {
|
|||
state.pos = start + 1;
|
||||
|
||||
// Earlier we checked !silent, but this implementation does not need it
|
||||
token = state.push("sup_open", "sup", 1);
|
||||
token.markup = "^";
|
||||
token = state.push("sup_open", "sup", 1);
|
||||
token.markup = "^";
|
||||
|
||||
if (content.match(regexForIds)) {
|
||||
const theLink = supText.match(regexForIds)[0].replace("(#", "").replace(")", "");
|
||||
token.attrPush([ "id", theLink ]);
|
||||
}
|
||||
|
||||
token = state.push("text", "", 0);
|
||||
token = state.push("text", "", 0);
|
||||
|
||||
if (content.match(regexForIds)) {
|
||||
const theText = supText.match(regexForTextBeforeLink)[0];
|
||||
token.content = theText;
|
||||
} else token.content = supText;
|
||||
|
||||
token = state.push("sup_close", "sup", -1);
|
||||
token.markup = "^";
|
||||
token = state.push("sup_close", "sup", -1);
|
||||
token.markup = "^";
|
||||
|
||||
state.pos = state.posMax + 1;
|
||||
state.posMax = max;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
|
||||
$(function () {
|
||||
|
||||
scrollToElementOnLoad();
|
||||
|
||||
$("a[href^=http]").each(function () { // Automatically open external links in new tabs
|
||||
|
@ -11,7 +10,6 @@ $(function () {
|
|||
$(this).attr("target", "_blank");
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -77,11 +77,6 @@ fastify.ready(err => {
|
|||
if (err) throw err;
|
||||
|
||||
fastify.ws.on("connection", socket => {
|
||||
socket.send(JSON.stringify({ // TODO: Remove this
|
||||
"message": "notification",
|
||||
"details": "Welcome"
|
||||
}));
|
||||
|
||||
socket.on("message", data => {
|
||||
data = JSON.parse(data);
|
||||
|
||||
|
@ -147,6 +142,7 @@ function fetchMetadata(data, socket) {
|
|||
|
||||
const allowedClaims = [
|
||||
"fortnite-top-stream-moments-nickatnyte",
|
||||
"hellolbry",
|
||||
"itsadisaster",
|
||||
"six",
|
||||
"unbubbled1-1"
|
||||
|
@ -203,7 +199,7 @@ function fetchMetadata(data, socket) {
|
|||
}, (error, response, body) => {
|
||||
if (error) reject(error);
|
||||
body = JSON.parse(body);
|
||||
console.log(body);
|
||||
// console.log(body);
|
||||
resolve(body);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
// https://github.com/lbryio/lbry/blob/master/docs/api.json
|
||||
// https://www.npmjs.com/package/make-fetch-happen
|
||||
|
|
|
@ -73,6 +73,8 @@ module.exports = exports = () => async state => {
|
|||
const markdownFile = fs.readFileSync(`./documents/${path}.md`, "utf-8");
|
||||
const markdownFileDetails = fm(markdownFile);
|
||||
const renderedMarkdown = md.render(partialFinder(markdownFileDetails.body));
|
||||
let newMetadata = "";
|
||||
if (markdownFileDetails.attributes.meta) newMetadata = markdownFileDetails.attributes.meta;
|
||||
|
||||
let pageScript = "";
|
||||
if (path === "overview") pageScript = "<script>" + fs.readFileSync("./views/partials/ecosystem-scripts.js", "utf-8") + "</script>";
|
||||
|
@ -92,6 +94,7 @@ module.exports = exports = () => async state => {
|
|||
<div class="inner-wrap">
|
||||
${raw(renderedMarkdown)}
|
||||
${raw(pageScript)}
|
||||
${newMetadata.length ? raw(updateMetadata(newMetadata)) : ""}
|
||||
</div>
|
||||
</section>
|
||||
</article>
|
||||
|
@ -100,7 +103,28 @@ module.exports = exports = () => async state => {
|
|||
|
||||
|
||||
|
||||
// H E L P E R
|
||||
// H E L P E R S
|
||||
|
||||
function createMetaTags(metaObject) {
|
||||
/**
|
||||
NOTE:
|
||||
For Markdown files, the custom yaml should look like this:
|
||||
|
||||
meta:
|
||||
- description: Description goes here
|
||||
|
||||
This does not currently work with parameters like "og:image"
|
||||
// https://github.com/lbryio/lbry.tech/issues/30
|
||||
*/
|
||||
|
||||
let html = "";
|
||||
|
||||
for (const metaProperty in metaObject) {
|
||||
html += `document.getElementsByTagName("meta")["${metaProperty}"].content = "${metaObject[metaProperty]}";\n`;
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
function partialFinder(markdownBody) {
|
||||
const regexToFindPartials = /<\w+\/>/g;
|
||||
|
@ -126,3 +150,17 @@ function partialFinder(markdownBody) {
|
|||
|
||||
return dedent(markdownBody); // partials get rendered as code snippets w/o `dedent`
|
||||
}
|
||||
|
||||
function updateMetadata(metadataDetails) {
|
||||
const generatedMetadata = [];
|
||||
|
||||
for (const metadataDetail of metadataDetails) {
|
||||
generatedMetadata.push(createMetaTags(metadataDetail));
|
||||
}
|
||||
|
||||
return dedent`
|
||||
<script>
|
||||
${generatedMetadata.join("")}
|
||||
</script>
|
||||
`;
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ module.exports = exports = class Ecosystem extends Component {
|
|||
|
||||
<p>The LBRY blockchain is a public, proof-of-work of work blockchain consensus. It is the foundation of the protocol stack.</p>
|
||||
|
||||
<p>The most salient feature of the LBRY blockchain is the association of a normalized character string with up to 8KB of metadata. This string of characters forms a LBRY URL, e.g. <a class="__plain" href="/tour?url=lbry://hellolbry"><code>lbry://hellolbry</code></a></p>
|
||||
<p>The most salient feature of the LBRY blockchain is the association of a normalized character string with up to 8KB of metadata. This string of characters forms a LBRY URL, e.g. <a class="__plain" href="/tour?url=hellolbry"><code>lbry://hellolbry</code></a></p>
|
||||
|
||||
<p>The LBRY blockchain contains two parallel [[Merkle Tree]]s, one for transactions (ala Bitcoin) and one for storing LBRY URLs and metadata. This allows LBRY URLs to be trustfully resolved even without a full copy of the blockchain.</p>
|
||||
|
||||
|
|
|
@ -6,6 +6,13 @@ initializeTour();
|
|||
|
||||
|
||||
|
||||
if (window.location.href.search && window.location.href.split("?url=")[1]) { // pre-fill Tour if search parameter exists
|
||||
const searchParameter = window.location.href.split("?url=")[1];
|
||||
fetchMetadata(1, searchParameter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$("body").on("click", "[data-action]", event => {
|
||||
event.preventDefault();
|
||||
const data = event.currentTarget.dataset;
|
||||
|
|
Loading…
Reference in a new issue