PetrSnobelt / UmbracoStaticPublish

Publish static documents from umbraco and optionally use it as cache
MIT License
8 stars 1 forks source link

UrlProvider #1

Open akeilox opened 9 years ago

akeilox commented 9 years ago

First of all a big thank you for sharing this method, its very exciting to see how simple it might be to have static version. For existing site does it work if you Republish entire site?

Well i tried to use it by adding the two files under AppCode (its a 7.1.4 installation) but Im gettin the following error, any ideas?

Compiler Error Message: CS1061: 'Umbraco.Web.UmbracoContext' does not contain a definition for 'UrlProvider' and no extension method 'UrlProvider' accepting a first argument of type 'Umbraco.Web.UmbracoContext' could be found (are you missing a using directive or an assembly reference?)

Source Error: Line 21: { Line 22: //must be inside Published block Line 23: var urlProvider = Umbraco.Web.UmbracoContext.Current.UrlProvider; Line 24: foreach (var content in args.PublishedEntities) Line 25: {

akeilox commented 9 years ago

Just managed to test this on both 7.1.2 and 7.1.4/6 and its having the same issue. When i test it on 7.2.4 it seems to work right off-the-box. Is there any way to make this work for the 7.1.x builds? This looks very promising and would love to get it to work on builds.

Also, what would you advise for handling the relative JS/CSS files, perhaps copying them to published folder would be the best - then one can use or copy the entire folder as static backup. Really really cool!

PetrSnobelt commented 9 years ago

Older umbraco versions: try put files in app_code, set breakpoint in Visual Studio and PR is welcomed

CSS/JS files - I try copy css, scripts, media and content of published folder into firebase hosting and it works (after fixing case sensitivity) but it totaly depend on your needs. I plan use publish folder as cache so I dont need copy files.

akeilox commented 9 years ago

Unfortunately I dont have VS on the systems... It works out-of-box in 7.2.4. However On 7.1.x installation (tried 4 different version installation of 7.1.x) I get the error above on Url Provider

" Umbraco.Web.UmbracoContext' does not contain a definition for 'UrlProvider' "

I think this is slighlty different on 7.1.x umbraco.web Dlls? I tried var urlProvider =Umbraco.Web.UmbracoContext.Current.RoutingContext.UrlProvider; but that didnt work either.

Would be great if this works in 7.1.x as postponing upgrading to 7.2.x due to inherit changes... Im sure anyone with VS and api knowledge can find whats wrong with it (i have neither).

For the use-case, beside the cache, I thought it can be used to copy the dependant files (css,js,media (most importantly)) to the target folder - which can be mapped to a linux remote host. Then it will be a quick fallback site, very elegant and simple! For initiating copy/one-way-sync of media files, do you advise to put a routine within the AppCode? Would that make sense, for automation/completeness?

Many thanks for sharing this.

akeilox commented 9 years ago

Ok, so I figured the UrlProvider is declared internal until 7.2.0, http://issues.umbraco.org/issue/U4-2581

If you are using any version before 7.2.0, one cant use this; var urlProvider1 = Umbraco.Web.UmbracoContext.Current.UrlProvider;

I really wanted to use this on 7.1.8, but cant seem to replace this to make it work for 7.1.8 install. Upgrading to 7.2.0 is not viable due to inherit changes.

Do you have any recommendation on possible alternate method? I couldnt find any after going through the forums.

akeilox commented 8 years ago

Just an update above, for other who wants/need to run the static publish code in 7.1.x versions (pre 7.2), one can replace the URLprovider code with the following to get the url:

var url = new UmbracoHelper(UmbracoContext.Current).NiceUrl(content.Id);
var absolutUrl = new UmbracoHelper(UmbracoContext.Current).UrlAbsolute(content.Id);