Skip to content
This repository has been archived by the owner on Aug 12, 2020. It is now read-only.

Markdown-Viewer (mdown) document title #36

Open
jbshirk opened this issue Oct 31, 2015 · 5 comments
Open

Markdown-Viewer (mdown) document title #36

jbshirk opened this issue Oct 31, 2015 · 5 comments

Comments

@jbshirk
Copy link
Contributor

jbshirk commented Oct 31, 2015

Using the latest version of mdown, I demonstrated to a potential client the elegant usefulness of this app for distributing content easily generated by the non-technical person. Client remarked (and I agree) that the browser tab <title> is hard-coded for all content passed to the app via #hash, and asked if there is a way to make the document title relevant to the specific content displayed. I tried an experiment, a modification, that assumes the first <h1> or <h2> that is generated from the markdown content is intended to be the doc title, and attempted to set the doc tile = firstheadingtext. I was not able to get it to work.

In a simple one-page.html document (not mdown) I confirmed that the following works:

 document.title = document.querySelector("h1, h2").textContent;

But in mdown it is not that simple. I was able to set the title to a dummy at the end of all scripts to verify that changing the location#hash does set the title. But the above code is out of the correct context and spins forever, never finding my <h2> generated from the .md file, and the debugger shows it returns NULL (not an object) so that in fact the page never finishes loading.

I was wondering if someone could give me some pointers on how to access the rendered DOM from within mdown to return the first heading's text. Better ideas are welcome. I am not a js person, if that explains my apparent cluelessness. Thanks!

@victorb
Copy link
Contributor

victorb commented Oct 31, 2015

The example you are showing (document.title = document.querySelector("h1, h2").textContent) should be working, I confirmed it with the javascript console when being here: https://ipfs.io/ipfs/QmSrCRJmzE4zE1nAfWPbzVfanKQNBhp7ZWmMnEdbiLvYNh/mdown#/ipfs/QmfQ75DjAxYzxMP2hdm6o4wFwZS5t7uorEZ2pX9AKXEg2u

The first thing I would try is to place you snipped after the content actually been loaded, and the loading have been hidden, which would be after this line: https://github.com/ipfs/examples/blob/master/webapps/markdown-viewer/mdown#L49

Otherwise, please show the code you're trying and maybe we can spot where things go wrong :)

@jbshirk
Copy link
Contributor Author

jbshirk commented Nov 1, 2015

That worked! Thank you so much!!

@jbshirk jbshirk closed this as completed Nov 1, 2015
@jbenet
Copy link
Contributor

jbenet commented Nov 1, 2015

could you please PR the changes? am sure everyone wants this

@jbshirk
Copy link
Contributor Author

jbshirk commented Nov 4, 2015

Unfortunately, I am not yet that savy with git. I cloned it to my local, and simply added the line where indicated. Check this: https://ipfs.io/ipfs/Qmbm4DRJd5eCMNeeHrtrJ4vYJGYAkbu2ZXtisb6C5ciWY1/md#uphold-holdup

I don't think people will want my changes, because I didn't want to use 'mdown' and changed it to 'md' as well as the reference to mdown in sample.md

@jbshirk
Copy link
Contributor Author

jbshirk commented Nov 4, 2015

Anyway, it is still suboptimal because the metadata scraped when posting to a site shows "markdown reader" as the title, which is hard-coded in the mdown html. I'd be interested in suggestions if this is of interest. Otherwise you can close it again if you want.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants