-
Notifications
You must be signed in to change notification settings - Fork 430
feat: support ipfs #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
thanks @olizilla for |
|
||
__webpack_public_path__ = ipfsPathPrefix + '/' | ||
if (typeof window !== 'undefined') { | ||
window.__VUEPRESS_ROUTER_BASE__ = ipfsPathPrefix + '/' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! this var is the secret ingredient, where did you find it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vuepress bootstrap code.
but __webpack_public_path__ = ipfsPathPrefix + '/'
this one is even more important without it the router would even load
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I knew there was a __webpack_public_path__
lurking about but I missed this one! Great work detective 🕵️♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah @satazor put me in the right direction with that one i just did the last mile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the highest of fives to @satazor! It also makes me wonder if we could make a more generic IPFS plugin for webpack compiled apps using some of these framework config vars. we'd need to do detection for router logic but it doesn't seem impossible now... 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I also thought about that in the past @cwaring and it’s doable. The route logic detection could also be pluggable, meaning we could have addons/plugins for typical frameworks such as Gatsby and Vue press.
I guess it would take some investment time but it would pay off later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, if we are delaying the adoption of origin isolation for a while then this might be a worthy endeavour to the community. I see this question crop up all the time.
Yes, I'm so happy we didn't have to regex the application source in the end! Do you think we could wrap this up neatly into a plugin by using https://vuepress.vuejs.org/plugin/option-api.html#chainwebpack to handle the path injection script? |
yes we should be able to build a plugin to do all this in one go, just need to figure out the last missing assets either but improving all-relative or in the plugin itself. |
@hugomrdias I'm guessing it would be helpful if I actually published all-relative to npm! |
It a thing https://www.npmjs.com/package/all-relative |
thanks @olizilla, so excited to see this all come together! |
51afa50
to
9b322dc
Compare
I've fixed the relative css path issues upstream in |
I think some head loads were failing also like manifest etc |
Yes I've noticed that too but they are not critical for launch and I don't think |
Hey folks! Thanks for providing this as a reference! I'm trying to add IPFS support on ethereum.org (ethereum/ethereum-org-website#751). I've copied your approach - it's up & running locally! This seems to have solved the issue with relative links. The only issue I see now is broken images from the /public dir. @hugomrdias - you mentioned that is your PR description. Did you find a solution to that? Thanks again. |
@samajammin ill take a look |
Hey @samajammin, great to see you drop in here and thanks for the email. I'll reply on this thread to keep the conversation open for others. I fixed all the docs asset path issues with the latest release of all-relative but if you have any config files with absolute paths (such as a favicon xml or app manifests) then these will need to be updated manually. In our case we decided to leave those considering the primary app will be loaded from the root domain and these were not critical to the functionality of the app on IPFS. vuepress-plugin-ipfs isn't ready just yet but I intend to port the functionality provided in this PR over to it after completing another project. Let me know how you get on and if we need to make any additional updates for this patch to be more accessible. |
Awesome, thanks for the guidance! So I now have the site pinned here: https://gateway.pinata.cloud/ipfs/QmZxrnb4P3RHcHpF7mTRzQ5x2vF1b5vZtWR23Ef5MsAcV9/ Looking at my build output in /docs/.vuepress/dist, the images seem to be relative links as intended but I'm seeing some inconsistent results on the IPFS gateway. e.g. sometimes I load this page & the images appear, with DOM inspection showing relative links: Sometimes I click to the page & the images are broken. The source shows they are not relative links: Do you see this as well? Any idea what may be causing the inconsistency here? It appears to be loading images correctly on page reloads but when navigating to this page from other routes, the images are broken. |
One more item I'm noticing - the mp4 file on our homepage is not referenced correctly: Looking at the build output HTML:
I believe the src should be |
Interesting, this isn't something we've seen on the docs project yet. It seems that VuePress is outputting absolute paths when the page/components re-render after routing. I haven't had chance to dig any deeper into your codebase but I wonder if it's something to do with how those individual assets are being included within the components? A couple of things I'd try next:
Let me know if either of these routes work and I'll aim to dig in as soon as I can. |
@samajammin curiosity got the better of me and I think I've found the culprit! If you are injecting asset paths into the markup dynamically (via strings) you will have to ensure they are relative. The easiest way to do this is to hook into A meta function like this should work ( const withBasePath = path => window && window.__VUEPRESS_ROUTER_BASE___ ? window.__VUEPRESS_ROUTER_BASE__ + path : '/' + path || '/' + path;
withBasePath('ethereum-hero-dark.mp4')
// => "/ipfs/QmZxrnb4P3RHcHpF7mTRzQ5x2vF1b5vZtWR23Ef5MsAcV9/ethereum-hero-dark.mp4" Let me know how it goes, I'll likely add a utility like this to the final plugin 🤙🏻 |
Or perhaps you could modify |
Thanks for the ideas @cwaring! I appreciate you taking the time to look into this. I tried your suggestion to create a When I have a chance (hopefully this week) I will keep experimenting but if you have any more ideas or if there's something you think I'm missing, please let me know. |
Here's the PR where I tried that update in case you'd like to experiment on your own: |
This PR adds support for hosting in IPFS.
Steps:
npx vuepress build docs
all-relative ./docs/.vuepress/dist
ipfs add ./docs/.vuepress/dist
Enjoy.
Theres still a couple of assests in the public folder that all-relative doesn't handle but that should be easy to fix.
Working example https://ipfs.io/ipfs/Qmb3bTUHXuxcuU9VWB5yG99Usa826kw4ZagyZJ5DucSZo3/