Skip to content

Commit

Permalink
Merge pull request #65 from AMISO-MY/cloudcannon
Browse files Browse the repository at this point in the history
Link Shortener
  • Loading branch information
ongzzzzzz authored Apr 7, 2024
2 parents 404833f + 5f3e828 commit db562c4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
7 changes: 7 additions & 0 deletions docs/_data/links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"title": "Example Link",
"short_link": "example",
"target_link": "https://example.com"
}
]
6 changes: 1 addition & 5 deletions docs/_includes/head/custom.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,4 @@
{% endfor %}
{% endif %}

<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{{ site.analytics.google.tag_manager_id }}');</script>
{%- include /head/gtm.html -%}
5 changes: 5 additions & 0 deletions docs/_includes/head/gtm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{{ site.analytics.google.tag_manager_id }}');</script>
12 changes: 12 additions & 0 deletions docs/_layouts/shortlink_redirect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0;url={{ page.redirect }}">
{%- include analytics.html -%}
<title>Redirecting to {{ page.title }}</title>
</head>
<body>
<p>If you are not redirected, <a href="{{ page.redirect }}">click here</a>.</p>
</body>
</html>
28 changes: 28 additions & 0 deletions docs/_plugins/redirect_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Jekyll
class RedirectPage < Page
def initialize(site, base, dir, name, title, target_link)
@site = site
@base = base
@dir = dir
@name = name
layout = site.layouts['shortlink_redirect']
self.process(@name)

self.read_yaml(File.join(base, '_layouts'), 'shortlink_redirect.html')
self.data['title'] = name
self.data['redirect'] = target_link
end
end

class RedirectGenerator < Generator
safe true
priority :low

def generate(site)
links = site.data['links']
links.each do |link|
site.pages << RedirectPage.new(site, site.source, File.join('go', link['short_link']), 'index.html', link['title'], link['target_link'])
end
end
end
end

0 comments on commit db562c4

Please sign in to comment.