很抱歉,这里的初学者尝试学习Firebase云功能并进行一些“嵌入”:
我创建了要点:https://gist.github.com/cmer4/840d729dd07b247db84dcc33ae3c219d.js
我可以将其嵌入到我的medium.com博客中:
现在,我想编写自己的云函数(firebase云函数)以类似于github.com对要点(840d729dd07b247db84dcc33ae3c219d.js)的响应:
document.write('<link rel="stylesheet" href="https://github.githubassets.com/assets/gist-embed-123720f37c57ce9a8f29de081c38ed61.css">')
document.write('<div id=\"gist100127887\" class=\"gist\">\n <div class=\"gist-file\">\n <div class=\"gist-data\">\n <div class=\"js-gist-file-update-container js-task-list-container file-box\">\n <div id=\"file-some-html\" class=\"file\">\n \n\n <div itemprop=\"text\" class=\"Box-body p-0 blob-wrapper data type-html \">\n \n<table class=\"highlight tab-size js-file-line-container\" data-tab-size=\"8\">\n <tr>\n <td id=\"file-some-html-L1\" class=\"blob-num js-line-number\" data-line-number=\"1\"><\/td>\n <td id=\"file-some-html-LC1\" class=\"blob-code blob-code-inner js-file-line\"><<span class=\"pl-ent\">ion-header<\/span> <span class=\"pl-e\">class<\/span>=<span class=\"pl-s\"><span class=\"pl-pds\">"<\/span>ion-padding-top<span class=\"pl-pds\">"<\/span><\/span>><\/td>\n <\/tr>\n <tr>\n <td id=\"file-some-html-L2\" class=\"blob-num js-line-number\" data-line-number=\"2\"><\/td>\n <td id=\"file-some-html-LC2\" class=\"blob-code blob-code-inner js-file-line\"> <<span class=\"pl-ent\">ion-toolbar<\/span>><\/td>\n <\/tr>\n <tr>\n <td id=\"file-some-html-L3\" class=\"blob-num js-line-number\" data-line-number=\"3\"><\/td>\n <td id=\"file-some-html-LC3\" class=\"blob-code blob-code-inner js-file-line\"> <<span class=\"pl-ent\">ion-buttons<\/span> <span class=\"pl-e\">slot<\/span>=<span class=\"pl-s\"><span class=\"pl-pds\">"<\/span>start<span class=\"pl-pds\">"<\/span><\/span>><\/td>\n <\/tr>\n <tr>\n <td id=\"file-some-html-L4\" class=\"blob-num js-line-number\" data-line-number=\"4\"><\/td>\n <td id=\"file-some-html-LC4\" class=\"blob-code blob-code-inner js-file-line\"> <<span class=\"pl-ent\">ion-back-button<\/span> <span class=\"pl-e\">defaultHref<\/span>=<span class=\"pl-s\"><span class=\"pl-pds\">"<\/span>/canvas<span class=\"pl-pds\">"<\/span><\/span>></<span class=\"pl-ent\">ion-back-button<\/span>><\/td>\n <\/tr>\n <tr>\n <td id=\"file-some-html-L5\" class=\"blob-num js-line-number\" data-line-number=\"5\"><\/td>\n <td id=\"file-some-html-LC5\" class=\"blob-code blob-code-inner js-file-line\"> </<span class=\"pl-ent\">ion-buttons<\/span>><\/td>\n <\/tr>\n <tr>\n <td id=\"file-some-html-L6\" class=\"blob-num js-line-number\" data-line-number=\"6\"><\/td>\n <td id=\"file-some-html-LC6\" class=\"blob-code blob-code-inner js-file-line\"> <<span class=\"pl-ent\">ion-title<\/span>>About</<span class=\"pl-ent\">ion-title<\/span>><\/td>\n <\/tr>\n <tr>\n <td id=\"file-some-html-L7\" class=\"blob-num js-line-number\" data-line-number=\"7\"><\/td>\n <td id=\"file-some-html-LC7\" class=\"blob-code blob-code-inner js-file-line\"> </<span class=\"pl-ent\">ion-toolbar<\/span>><\/td>\n <\/tr>\n <tr>\n <td id=\"file-some-html-L8\" class=\"blob-num js-line-number\" data-line-number=\"8\"><\/td>\n <td id=\"file-some-html-LC8\" class=\"blob-code blob-code-inner js-file-line\"></<span class=\"pl-ent\">ion-header<\/span>><\/td>\n <\/tr>\n<\/table>\n\n\n <\/div>\n\n <\/div>\n<\/div>\n\n <\/div>\n <div class=\"gist-meta\">\n <a href=\"https://gist.github.com/cmer4/840d729dd07b247db84dcc33ae3c219d/raw/625f0782ea96af8abe84ee1410e0a8219d0fd1ea/some.html\" style=\"float:right\">view raw<\/a>\n <a href=\"https://gist.github.com/cmer4/840d729dd07b247db84dcc33ae3c219d#file-some-html\">some.html<\/a>\n hosted with ❤ by <a href=\"https://github.com\">GitHub<\/a>\n <\/div>\n <\/div>\n<\/div>\n')
为此,我试图做的很天真
exports.respondWithJavascript = functions.https.onRequest((req, res) => {
res.set('Content-Type', 'text/javascript');
let jsFile = "document.write('<link rel=\"stylesheet\" href=\"https://github.githubassets.com/assets/gist-embed-123720f37c57ce9a8f29de081c38ed61.css\">') document.write('<div id=\"gist100127887\" class=\"gist\">\n <div class=\"gist-file\">\n <div class=\"gist-data\">\n <div class=\"js-gist-file-update-container js-task-list-container file-box\">\n <div id=\"file-some-html\" class=\"file\">\n \n\n <div itemprop=\"text\" class=\"Box-body p-0 blob-wrapper data type-html \">\n \n<table class=\"highlight tab-size js-file-line-container\" data-tab-size=\"8\">\n <tr>\n <td id=\"file-some-html-L1\" class=\"blob-num js-line-number\" data-line-number=\"1\"><\/td>\n <td id=\"file-some-html-LC1\" class=\"blob-code blob-code-inner js-file-line\"><<span class=\"pl-ent\">ion-header<\/span> <span class=\"pl-e\">class<\/span>=<span class=\"pl-s\"><span class=\"pl-pds\">"<\/span>ion-padding-top<span class=\"pl-pds\">"<\/span><\/span>><\/td>\n <\/tr>\n <tr>\n <td id=\"file-some-html-L2\" class=\"blob-num js-line-number\" data-line-number=\"2\"><\/td>\n <td id=\"file-some-html-LC2\" class=\"blob-code blob-code-inner js-file-line\"> <<span class=\"pl-ent\">ion-toolbar<\/span>><\/td>\n <\/tr>\n <tr>\n <td id=\"file-some-html-L3\" class=\"blob-num js-line-number\" data-line-number=\"3\"><\/td>\n <td id=\"file-some-html-LC3\" class=\"blob-code blob-code-inner js-file-line\"> <<span class=\"pl-ent\">ion-buttons<\/span> <span class=\"pl-e\">slot<\/span>=<span class=\"pl-s\"><span class=\"pl-pds\">"<\/span>start<span class=\"pl-pds\">"<\/span><\/span>><\/td>\n <\/tr>\n <tr>\n <td id=\"file-some-html-L4\" class=\"blob-num js-line-number\" data-line-number=\"4\"><\/td>\n <td id=\"file-some-html-LC4\" class=\"blob-code blob-code-inner js-file-line\"> <<span class=\"pl-ent\">ion-back-button<\/span> <span class=\"pl-e\">defaultHref<\/span>=<span class=\"pl-s\"><span class=\"pl-pds\">"<\/span>/canvas<span class=\"pl-pds\">"<\/span><\/span>></<span class=\"pl-ent\">ion-back-button<\/span>><\/td>\n <\/tr>\n <tr>\n <td id=\"file-some-html-L5\" class=\"blob-num js-line-number\" data-line-number=\"5\"><\/td>\n <td id=\"file-some-html-LC5\" class=\"blob-code blob-code-inner js-file-line\"> </<span class=\"pl-ent\">ion-buttons<\/span>><\/td>\n <\/tr>\n <tr>\n <td id=\"file-some-html-L6\" class=\"blob-num js-line-number\" data-line-number=\"6\"><\/td>\n <td id=\"file-some-html-LC6\" class=\"blob-code blob-code-inner js-file-line\"> <<span class=\"pl-ent\">ion-title<\/span>>About</<span class=\"pl-ent\">ion-title<\/span>><\/td>\n <\/tr>\n <tr>\n <td id=\"file-some-html-L7\" class=\"blob-num js-line-number\" data-line-number=\"7\"><\/td>\n <td id=\"file-some-html-LC7\" class=\"blob-code blob-code-inner js-file-line\"> </<span class=\"pl-ent\">ion-toolbar<\/span>><\/td>\n <\/tr>\n <tr>\n <td id=\"file-some-html-L8\" class=\"blob-num js-line-number\" data-line-number=\"8\"><\/td>\n <td id=\"file-some-html-LC8\" class=\"blob-code blob-code-inner js-file-line\"></<span class=\"pl-ent\">ion-header<\/span>><\/td>\n <\/tr>\n<\/table>\n\n\n <\/div>\n\n <\/div>\n<\/div>\n\n <\/div>\n <div class=\"gist-meta\">\n <a href=\"https://gist.github.com/cmer4/840d729dd07b247db84dcc33ae3c219d/raw/625f0782ea96af8abe84ee1410e0a8219d0fd1ea/some.html\" style=\"float:right\">view raw<\/a>\n <a href=\"https://gist.github.com/cmer4/840d729dd07b247db84dcc33ae3c219d#file-some-html\">some.html<\/a>\n hosted with ❤ by <a href=\"https://github.com\">GitHub<\/a>\n <\/div>\n <\/div>\n<\/div>\n')";
res.send(jsFile)
})
现在我在这里有了端点: https://us-central1-morphistic-base.cloudfunctions.net/respondWithJavascript
但是不允许我嵌入代码吗?是我的功能出现问题,还是由于medium.com而无法正常工作?
答案 0 :(得分:1)
您之所以能够将要旨嵌入到诸如Medium(我假设您在此处显示的内容)这样的博客平台中,之所以成为Medium,是因为toon material。它识别出URL是要旨,并从中创建丰富的内容。此类嵌入仅适用于Medium已集成的产品。您不能仅通过将任何URL粘贴到其中来创建自己的集成。