The answer provided by PeterInvincible was almost perfect, however there is no need to connect the pipeline to remove ...
The following will also produce the desired result.
{{ page.url | replace:'/',' ' | truncatewords: 1,"" }}
And to save it in a variable, use capture redirection
{{ capture url_base }}{{ page.url | replace:'/',' ' | truncatewords: 1,"" }}{{ endcapture }}
which is called via {{url_base}} or mixed with other processing calls.
Also for file paths, instead of page.dir URLs, page.dir works well if you do not use the permalink settings for the layout, check the gh-pages branch (in particular _includes/nav_gen.html for functional, albeit rough edges, example) for hosted examples of similar code examples related to fluid syntax and other magic.
Editing and Updates
The above script now works in real time / basically, it works / modularly and is automatically serviced by parsed subdirectories currently viewed on the corresponding project website https://s0ands0.imtqy.com/Perinoid_Pipes/ , where examples of recursive directory parsing are presented . Inclusion and modification for almost any topic should be possible, just check the comment at the top for currently recognized commands that can be transmitted when the call is turned on ... on this inclusion and modulation note, here is how to include the above code for parsing directory in function
{% comment %} # Save this to _include/dir_path_by_numbers.html # import with the following assigning arguments if needed # {% include dir_path_by_numbers.html directory_argument_path="blog" directory_argument_depth=1 %} {% endcomment %} {% assign default_arg_directory_path = page.url %} {% assign default_arg_directory_depth = 1 %} {% if directory_argument_path %} {% assign directory_to_inspect = directory_argument_path %} {% else %} {% assign directory_to_inspect = default_arg_directory_path %} {% endif %} {% if directory_argument_depth %} {% assign directory_to_inspect_depth = directory_argument_path %} {% else %} {% assign directory_to_inspect_depth = default_arg_directory_depth %} {% endif %} {% comment %} # Defaults read and assigned now to output results {% endcomment %} {{ directory_to_inspect_depth | replace:'/',' ' | truncatewords: directory_to_inspect_depth,"" | remove_first: '/' | replace:' ','/' }}
The above should output the directory path length of any desired size and possibly turn on as shown earlier, or if you feel adventurous, try what is shown below; although for looping and recursive functions, see the related script for how I worked on stack size limits.
{% capture dir_sub_path %}{{include dir_path_by_numbers.html directory_argument_path="blog" directory_argument_depth=1}}{% endcapture %}
The note above is just speculation, untested and possibly more buggy than proven scripts and public publishing ... in other words, inspiration.