Masking download links

As Google and other search engines are to eager to index links to files, as well users like to share links to PDF on your site I am thinking, is there any way to mask download in Hugo? maybe Shortcode?

There is clever option to add aliases to posts in markdown, and wonder if something like that can be achiever for pdf files.

/downloads/file1/ > /download/files/file1.pdf

What I want to achieve is that I can trace downloads. On a page that will be fired to download file will be minimal analytics included so I can see that this was downloaded.

Just an idea, not sure if currently is possible etc.

Also, users who want to share link, they will share to masked instead pure link to PDF file. That will give greater control whats on other side of the masked URL as well prevent from (show from where) draining transfer on your account.

Typically I use rel="noopener" for links that I do not want indexed by bots and spiders.

However there is also another approach.

@martignoni has published a Hugo theme component for cloaking email addresses.

With the above an email address is outputted in HTML by Hugo as a random string and then it is re-assembled on the front-end with JS.

I suppose that you could adapt it to mask download links.

Will try, thank you.

I am pretty sure that is not what this is for. You should use rel=“noopener nofollow” for that. the noopener relation is to indicate to the browser, that it should start a new system process for the new page and should forget all data from the page where it came from (for instance history related info). You should use that for all external links to make sure those websites can’t use things like history anything lingering in the browser session being available to them.

So in general for local download links use nofollow, for external links use noopener. These things can be set also via headers. I am thinking about noindex nofollow for everything with the ending PDF for instance.

You can add multiple rel-items via space separated list.

2 Likes

Not a full answer either, but I would approach this the following way:

  • add a custom output type for PDF
  • have the PDF created via Hugo
  • locate the PDF markdown content in /content/path/something/pdfname
  • add alias: ['downloadlinkpath']
  • link only to the alias and let Hugo do the redirects.

Problem with this approach: If I check the page headers in the browser console I see that the site is forwarding to the proper PDF location.

You might be able to solve a real safe solution where the user does not know the final link with AWS or a service like that.

Yes. That is what I am using. But I wrote half of it, as I am in the middle of something else. Thanks for pointing it out.

2 Likes

This, will look at that as well.

Not really bother if somebody would like to get link from source of the page, as that will be like 1% of people :slight_smile: