In Jekyll (i.e. Markdown), is it possible to split the base portion of given urls between links?

The MD syntax allows two main communication methods: [title](link)

and [title][reference]

. [reference]

can be used multiple times in a document, but that's only for absolute URLs.

What if I'm doing a code blog and linking to API docs a lot, so many URLs start the same way, for example http://developer.android.com/reference/android/

as a base for http://developer.android.com/reference/android/content/Context.html

. Is there a way to modulate such links?

Maybe there is another choice besides Markdown that is Jekyll compatible? Plugin? It looks like this would be a common need.

Related: How to set base url for markdown links in IPython?

+3


source to share


1 answer


I personally use the link library (include) which I can use in any post or page.

Note: if the site is not in the root of the domain (for example: localhost / or example.com/) and lives in a subfolder (for example: localhost / subfolder /), we need to add internal links with the value site.baseurl

<!--- file : _includes/_links_library.markdown --->

<!--- POSTS --->
[welcome]: {{site.baseurl}}{% post_url 2014-09-09-welcome-to-jekyll %}

<!--- PAGES --->
[index]: {{site.baseurl}}/subfolder/
[file]: {{site.baseurl}}/subfolder/file.html

<!--- EXTERNAL PAGES --->
[jekyll]: http://jekyllrb.com/

<!--- ANDROID API REF --->
{% assign androidRef = "http://developer.android.com/reference/android" %}
[context]: {{ androidRef }}/content/Context.html

      



Then we need to include our library in order to use such links:

---
front matter
---

Link to [welcome post][welcome]
Link to [index][]
Link to [Jekyll doc][jekyll]

{% include _links_library.markdown %}

      

+2


source







All Articles