diff --git a/modules/markdown-it-sup.js b/modules/markdown-it-sup.js index 3dfa71f..7973b36 100644 --- a/modules/markdown-it-sup.js +++ b/modules/markdown-it-sup.js @@ -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; diff --git a/public/scripts/app.js b/public/scripts/app.js index 16d1b71..ee4e83c 100755 --- a/public/scripts/app.js +++ b/public/scripts/app.js @@ -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"); } }); - }); diff --git a/server.js b/server.js index b31a35c..2fdfb19 100755 --- a/server.js +++ b/server.js @@ -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); }); }); diff --git a/views/pages/_api.js b/views/pages/_api.js index 920953d..a2b62c5 100644 --- a/views/pages/_api.js +++ b/views/pages/_api.js @@ -1 +1,2 @@ +// https://github.com/lbryio/lbry/blob/master/docs/api.json // https://www.npmjs.com/package/make-fetch-happen diff --git a/views/pages/page.js b/views/pages/page.js index 9bc0420..8bccea3 100644 --- a/views/pages/page.js +++ b/views/pages/page.js @@ -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 = ""; @@ -92,6 +94,7 @@ module.exports = exports = () => async state => {
${raw(renderedMarkdown)} ${raw(pageScript)} + ${newMetadata.length ? raw(updateMetadata(newMetadata)) : ""}
@@ -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` + + `; +} diff --git a/views/partials/ecosystem.js b/views/partials/ecosystem.js index 7c2a35c..728ad4c 100644 --- a/views/partials/ecosystem.js +++ b/views/partials/ecosystem.js @@ -140,7 +140,7 @@ module.exports = exports = class Ecosystem extends Component {

The LBRY blockchain is a public, proof-of-work of work blockchain consensus. It is the foundation of the protocol stack.

-

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. lbry://hellolbry

+

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. lbry://hellolbry

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.

diff --git a/views/partials/tour-scripts.js b/views/partials/tour-scripts.js index 7c0bc70..c1ed28c 100644 --- a/views/partials/tour-scripts.js +++ b/views/partials/tour-scripts.js @@ -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;