1919# Example conversions:
2020#
2121# French
22- # partiellement-faux-le-gouvernement-sénégalais-na-pas-été-dissout-après-les-manifestations-du-19 ->
22+ # partiellement-faux-le-gouvernement-sénégalais-na-pas-été-dissout-après-les-manifestations-du-19-5a7e55071173 ->
2323# partiellement-faux-le-gouvernement-s-c3-a9n-c3-a9galais-na-pas--c3-a9t-c3-a9-dissout-apr-c3-a8s-les-manifestations-du-19
2424#
2525# Amharic
26- # የፈጠራ-ወሬ-የየመን-ሚሳኤል-በእስራኤል-ላይ-ያደረሰውን-ጥቃት-ያሳይሉ-የተባሉት-እነዚህ-ሁለት-ፎቶዎች-የተቀነባበሩ-ናቸውi ->
26+ # የፈጠራ-ወሬ-የየመን-ሚሳኤል-በእስራኤል-ላይ-ያደረሰውን-ጥቃት-ያሳይሉ-የተባሉት-እነዚህ-ሁለት-ፎቶዎች-የተቀነባበሩ-ናቸው-36aa9b306317 ->
2727# -e1-8b-a8-e1-8d-88-e1-8c-a0-e1-88-ab--e1-8b-88-e1-88-ac--e1-8b-a8-e1-8b-a8-e1-88-98-e1-8a-95--e1-88-9a-e1-88-b3-e1-8a-a4-e1-88-8d--e1-89-a0-e1-8a-a5-e1-88-b5-e1-88-ab-e1-8a-a4-e1-88-8d-
2828#
2929# English
30- # false-ugandas-education-minister-janet-museveni-has-not-ordered-schools-to-end-their-third-term ->
31- # false-ugandas-education-minister-janet-museveni-has-not-ordered-schools-to-end-their-third-term (No change as expected)
30+ # false-ugandas-education-minister-janet-museveni-has-not-ordered-schools-to-end-their-third-term-4ef52ad31a17 ->
31+ # false-ugandas-education-minister-janet-museveni-has-not-ordered-schools-to-end-their-third-term
3232#
3333
3434
@@ -53,10 +53,16 @@ server {
5353 lingering_timeout 5s;
5454 send_timeout 60s;
5555
56- include {{ .DOKKU_ROOT }}/{{ .APP }}/nginx.conf.d/*.conf;
56+ # Remove the random ID that Medium appends to post URLs. This effectively does the same redirect recommended by Ghost here:
57+ # https://docs.ghost.org/migration/medium#using-custom-domains
58+ # Note: This rewrite happens before the redirect to HTTPS
59+ rewrite "^/(.*)(-[0-9a-f]{10,12})$" /$1 permanent;
60+
5761 location / {
5862 return 301 https://$host:443$request_uri;
5963 }
64+ include {{ .DOKKU_ROOT }}/{{ .APP }}/nginx.conf.d/*.conf;
65+
6066}
6167
6268server {
@@ -79,7 +85,6 @@ server {
7985 lingering_timeout 5s;
8086 send_timeout 60s;
8187
82-
8388 location / {
8489 gzip on;
8590 gzip_min_length 1100;
@@ -88,12 +93,17 @@ server {
8893 gzip_vary on;
8994 gzip_comp_level 6;
9095
91- # Remove the random ID that Medium appends to post URLs. This effectively does the same redirect recommended by Ghost here:
92- # https://docs.ghost.org/migration/medium#using-custom-domains
93- rewrite "^/(.*)(-[0-9a-f]{10,12})$" /$1 permanent;
94-
9596 # Check if conversion is needed using the map
9697 access_by_lua_block {
98+ -- First check for Medium ID and remove it before processing
99+ local has_medium_id = string.match(ngx.var.uri, "/(.*)-([%x][%x][%x][%x][%x][%x][%x][%x][%x][%x][%x]?[%x]?)$")
100+ if has_medium_id then
101+ -- Remove Medium ID and redirect to the cleaned URL
102+ local clean_path = string.gsub(ngx.var.uri, "/(.*)-([%x][%x][%x][%x][%x][%x][%x][%x][%x][%x][%x]?[%x]?)$", "/%1")
103+ ngx.redirect(clean_path, 301)
104+ return
105+ end
106+
97107 if ngx.var.needs_conversion == "yes" then
98108 local function convert_string(input_str)
99109 -- Split the input string by hyphens
0 commit comments