szaktárca
információteknikológiailag

Emberi fogyasztásra alkalmas URL címek a blogjaimban

December 16, 2007 00:49 by e-Musty

Mert e-Musty úgyse bírja ki. Hetekig nem mertem még kicsomagolni sem a BlogEngine.NET forráskódját, előre féltem tőle, hogy hány tucat konfigurációs hibán kell végigrágnom magam, mire sikerül egyáltalán a saját gépemen lefordítani a BlogEngine.NET-et, erre meg mi történt? Elsőre fordult. Most idézhetném BM barátom szavait: mert ez technológia wazze. :)

Na, szóval már az első BlogEngine.NET-es naptól kezdve bántott két dolog. Az egyik probléma az volt, hogy a blogbejegyzések saját URL-jének (smart URL-jének, slugjának stb.) előállításakor a bejegyzéscímben lévő ékezetes betűket nem ékezet nélküli hasonmásokra cserélte, hanem HTML-entitásokra. Így lett volna az Űrhajó című bejegyzés címe http://blog.e-Musty.hu/szaktarca/-Uumlrhaj-oacute.aspx az olvasható http://blog.e-Musty.hu/szaktarca/Urhajo.aspx helyett.

A másik probléma nemében hasonlított az előzőhöz: ha asztali kliensből blogoltam – én a Windows Live Writerből szoktam –, és a böngészőben megnyitottam szerkesztésre egy bejegyzést, akkor ugyanez történt, a kulturált ékezetes szöveg helyett HTML-kódos szöveget láttam a cím mezőben.

A két probléma össze is függöt, ugyanis a BlogEngine.NET sluggyártója a bejegyzés címéből generál slugot (persze lehet sajátot is kitalálni), amiben viszont eleve HTML-tagek voltak.

Gondoltam, teszek egy próbát, a nyomára bukkanok, hol történik a sluggyártás, és megpróbálom megcsinálni. Még mindig nem hiszem el, de elsőre sikerült.

Ehhez mindössze a következő kódváltoztatást kellett eszközölnöm az Utils.cs fájlban:

public static string RemoveIllegalCharacters(string text)
    {
      if (string.IsNullOrEmpty(text))
        return text;
  
      text = text.Replace(":", "-");
      text = text.Replace("/", "-");
      text = text.Replace("?", "-");
      text = text.Replace("#", "-");
      text = text.Replace("[", "-");
      text = text.Replace("]", "-");
      text = text.Replace("@", string.Empty);
      text = text.Replace(".", string.Empty);
      text = text.Replace("\"", "-");
      text = text.Replace("&", "-");
      text = text.Replace("%", "-");
      
      // e-Musty inserted - removing some more illegal chars
      text = text.Replace(",", string.Empty);
      text = text.Replace("–", "-");
      text = text.Replace("á", "a");
      text = text.Replace("Á", "A");
      text = text.Replace("é", "e");
      text = text.Replace("É", "E");
      text = text.Replace("í", "i");
      text = text.Replace("Í", "I");
      text = text.Replace("ó", "o");
      text = text.Replace("Ó", "O");
      text = text.Replace("ö", "o");
      text = text.Replace("Ö", "O");
      text = text.Replace("ő", "o");
      text = text.Replace("Ő", "O");
      text = text.Replace("ú", "u");
      text = text.Replace("Ú", "U");
      text = text.Replace("ü", "u");
      text = text.Replace("Ü", "U");
      text = text.Replace("ű", "u");
      text = text.Replace("Ű", "U");
      // eof e-Musty inserted
  
      return HttpUtility.UrlEncode(text.Replace(" ", "-"));
    }

 

Ezt a metódust egy callback-mechanizmus hívja a slug automatikus generálása vagy a kézzel beírt slug ellenőrzése során (Add_entry.aspx.cs).

Ekkor már majdnem jól működött minden, leszámítva, hogy a Live Writer, ahogy azt rendesen kell, a MetaWeblogAPI-s XML-csomagjában HTML-entitásokká alakította az ékezeteket, ezért ezek eleve entitásként érkeztek a blogmotorhoz. Vagyis hiába cserélte volna a szerencsétlen e betűre az é betűt, ha é betű helyett az é karakterláncot kapta.

Ennek megoldása még egyszerűbb volt: a MetaWeblogHandler.cs fájl NewPost metódusában a

post.Title = sentPost.title;

 

sort a

post.Title = HttpUtility.HtmlDecode(HttpUtility.UrlDecode(sentPost.title));

 

sorra kellett cserélni – megjegyzem, lehet hogy a HttpDecode előtt túlzás URL-dekódolást is kérni, de biztosra akartam menni. :)

És most nagyon jól működik, én pedig majd sok-sok mindent fogok belefejleszteni a BlogEngine.NET-be, mert e-Musty úgyse bírja ki. :)


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Comments

November 5. 2009 19:53

payday loans

thanks! very helpful post!! like the template btw Wink

payday loans

December 29. 2009 13:00

MS Payday Loans

Interesting post

MS Payday Loans

March 5. 2010 11:10

MS Payday Loans

Coming together is a beginning, staying together is progress, and working together is success.

MS Payday Loans

April 28. 2010 15:00

Rapidshare

I\'m happy I found this blog, I couldnt discover any info on this subject matter prior to. I also run a site and if you want to ever serious in a little bit of guest writing for me if possible feel free to let me know, i\'m always look for people to check out my site. Please stop by and leave a comment sometime!

Rapidshare

May 21. 2010 17:48

make money from your pc

The art of making money from your computer can be a complex one to learn, but if you have all the right information in front of you then making money at home from your computer is easy

make money from your pc

June 15. 2010 19:07

Svitlana.Net.Ua

I would like to thank you for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now.

Svitlana.Net.Ua

June 17. 2010 17:19

няня

I would like to thank you for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now.
http://svitlana.net.ua/staff/category/3/ гувернантка, http://svitlana.net.ua/staff/category/5/ повар, http://svitlana.net.ua/staff/category/6/ садовник, http://svitlana.net.ua/staff/category/10/ репетитор, http://svitlana.net.ua/staff/category/4 домработница, http://svitlana.net.ua/staff/category/8/ семейная пара, http://svitlana.net.ua/pages/2/ работа няней.

няня

June 23. 2010 22:06

Проститутки-индивидуалки

И вот, настал тот день, когда мы уже готовимся к отъезду. В голове сразу проплывает картина будущей поездки: дорога, на которой стоят проститутки Сочи, проезжающие мимо машины, с такими же туристами, атмосфера спокойствия и не напряженности, в голове, кроме мыслей об отдыхе, нет ничего другого, что может отвлечь нас от этого.

Проститутки-индивидуалки

June 27. 2010 04:59

Покер

It\'s an intriguing approach. I ordinarily stumble upon ordinary thoughts on the theme but yours it\'s written in a pretty special way. Sure enough, I will revisit your website for additional information.

Покер

July 5. 2010 00:23

Магазин сантехники

I like your blog so much that I feel I have to wish you. Happy New Year in advance. Have a nice and prosperous year ahead

Магазин сантехники

July 8. 2010 06:49

Индивидуалка Москвы

You made fantastic nice points here. I performed a search on the issue and discovered almost all peoples will agree with your blog.

Индивидуалка Москвы

July 10. 2010 23:57

Проститутки

You gave nice ideas here. I done a research on the issue and learnt most peoples will agree with your blog. Certainly, these practices are unfair; but they say that most of their rules are only to apply to people who overdraw.

Проститутки

July 11. 2010 21:35

Новинки сантехники

You have some honest ideas here. I done a research on the issue and discovered most peoples will agree with your blog.

Новинки сантехники

July 20. 2010 05:56

mexican illegal immigration laws

"Keep your face to the sunshine and you cannot see the shadow." Helen Adams Keller

mexican illegal immigration laws

July 20. 2010 14:35

illegal immigration statistics 2009

We are what we think. Buddha

illegal immigration statistics 2009

July 21. 2010 09:48

extenze

I'm very glad that I found your website. My friend mentioned it before, but I never got around to checking it out until now. I enjoyed reading your posts and will be back to read more very soon.

extenze

Add comment


(Will show your Gravatar icon)  

  Country flag





Live preview

July 29. 2010 22:21