问题
Both Umbraco/TinyMce both like to strip the base domain from any absolute URLs in the editor. This is problematic as I have an RSS feed that scrapes my posts, and emails them weekly to subscribers. The issue is, images (and links, but I'll worry about that later) obviously won't work if their URL is relative.
So far I've done the following:
1) Added to tiny_mce_src.js:
convert_urls : false,
relative_urls : false,
remove_script_host : false,
Contrary to what's out there, for Umbraco convert_urls must be set to false.
Using the media content picker (or built in HTML editor), this will preserve what is typed (until saving/publishing..). Otherwise it strips out the base domain upon closing the media content picker or built in HTML editor.
2) The next issue is that content creators will not want to mess around with HTML, so I needed the media picker to automatically have the base domain when picking a picture. I hardcoded this in here in insertImage.js:
if (src.substring(0, umbracoPath.length) == umbracoPath) {
// if the path contains a reference to the umbraco path, it also contains a reference to go up one level (../)
src = src.substring(umbracoPath.length + 3, src.length);
}
var formObj = document.forms[0];
formObj.src.value = 'https://example.com' + src;
This fixes everything up until publishing and saving. Basically, somewhere in this jungle gym of a framework it grabs the current domain and subdomain if applicable, and if that domain is in the Rich Content Editor box (such as in a link or image href/src) it will.. strip it out.
A work around for this to use https://www.example.com/ in the insertImage.js code above, and make sure you're accessing the back office via just https://example.com.
This, however, will not work as I will have some content creators using www and some that will not be. Also even if I didn't hardcode and instead said if www is in current domain then not www (and vice versa) in insertImage.js, it would eventually cause issues if Employee A (using www) went to an old post that Employee B did (not using www) and resaved- It would push it back to a relative URL.
My question is: Where can I look in the Umbraco framework to edit the source of this issue directly?
回答1:
An alternative is to use a parser, regex, or substring methods. I also don't have to worry about maintaining any changes I would have made to the Umbraco framework.
I ended just using a simple substring at the very moment I'm calling this information for the RSS feed:
var bt = node.GetProperty("bodyText").Value
.Replace("src=\"/","src=\"https://example.com/")
.Replace("href=\"/","href=\"https://example.com/");
@Html.Raw(bt);
Any src and href attributes with a forward slash as the first character will get replaced with the base domain name. This works perfectly for my setup, but might cause issues if you were displaying code in a blog post, for example.
A parser such as HTML Agility Pack pack is better, but I don't need it if I can solve my issue with technically 1 new line of code.
来源:https://stackoverflow.com/questions/29776113/stop-umbraco-tinymce-from-converting-absolute-urls-to-relative-urls