Split path

{% assign crumbs = page.url | split: '/' %}

For page with URL /demo/python/pypi.html:

{{ crumbs | inspect }}
["", "demo", "python", "pypi.html"]

Recombine:

{{ crumbs | join: '/' }}
/demo/python/pypi.html

Use just a portion of the URL:

{{ crumbs | slice: 0, 3 | join: '/' }}
/demo/python