Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (directus-extension-permalink-generator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Directus CMS Permalink Generator Extension
Auto-generate hierarchical permalinks for pages in Directus based on parent-child relationships.
Installation
This extension supports Directus 11.x. In the root of your Directus server project run:
$ npm i directus-extension-permalink-generator
... and then restart Directus!
Note: If you are running Directus on docker, you need to install the extension in the directory extensions of the Directus server. Reference here for docker-compose file:
https://github.com/letrthang/directus-app/blob/master/docker-compose.yml.
Or simply run:
$ npm i directus-extension-permalink-generator
and then copy directory from:
node_modules/directus-extension-permalink-generator
to extensions/directus-extension-permalink-generator and restart Directus docker.
Prerequisites
- Directus 11.x
- Node.js 18+
- npm or yarn
- Install CMS template into Directus if it hasn't installed.
Below is example of installation CMS template on Directus Docker console (
npx directus-template-cli@latest apply)
Development
Step 1: Configure Pages Collection
Add a parent-child relationship to your Pages collection:
- Open Directus Admin Panel
- Navigate to Settings → Data Model → Pages
- Click Create Field
- Field name:
parent - Field type: Many to One Relationship
- Related collection: Pages (self-referential)
- Save the field
=> Repeating above steps to create other parent field with name is 'other_parent'. You can create many parent fields as you want.
This enables hierarchical page structures where pages can have parent pages.
Step 2: Build the Extension
Clone and build the extension locally:
# Clone the repository
git clone https://github.com/letrthang/directus-cms-permalink-generator
cd directus-cms-permalink-generator
# Install dependencies
npm install
# Build the extension
npm run buildThe built extension will be in the dist/ folder.
Step 3: Deploy to Directus
Copy the extension to your Directus installation:
For Local Docker installations:
Assuming you already have docker-compose installation for Directus.
If not, here is a reference of docker-compose: https://github.com/letrthang/directus-app
# Copy to your mounted extensions directory
cp -r dist ./extensions/directus-extension-permalink-generator/
cp package.json ./extensions/directus-extension-permalink-generator/
# Restart Docker Directus
docker-compose restartStep 4: Configure the Permalink Field
- Go to Settings → Data Model → Pages
- Click on the permalink field
- Under Interface, select Permalink Generator
- Input Title field and Parent page which are existing in the data model/schema
- Save changes
Usage
When creating or editing a page:
- Enter the page Title which you configured at the Permalink interface
- Optionally select a Parent page which you configured at the Permalink interface. Note: a page cannot set parent is itself
- Click the Generate URL button next to the permalink field
- The permalink will be automatically generated based on the hierarchy
Examples
Single-level page:
- Title: "About Us"
- Parent: None
- Generated:
/about-us
Two-level page:
- Title: "Our Team"
- Parent: "About Us"
- Generated:
/about-us/our-team
Three-level page:
- Title: "Management"
- Parent: "Our Team" (which has parent "About Us")
- Generated:
/about-us/our-team/management
Features
- Automatic slug generation from page titles
- Hierarchical URL structure based on parent relationships
- URL-safe character conversion (spaces to hyphens, remove special chars)
- Success/error notifications
- Works with both new and existing pages
- Real-time generation with loading state
Development
Run in development mode with hot reload:
npm run devDebugging
Enable debug logging in browser console (F12):
- Open browser DevTools
- Go to Console tab
- Click "Generate URL" button
- View detailed logs showing the generation process
Troubleshooting
Extension not appearing:
- Verify the extension folder is named
directus-extension-permalink-generator - Check Directus logs:
docker-compose logs -f directus - Ensure
package.jsonhas"host": "^11.0.0" - Extension must be in
extensions/directory (notextensions/interfaces/)
Generate button not working:
- Check browser console (F12) for errors
- Ensure the
parentfield exists in the Pages collection - Verify API permissions allow reading page data
- Make sure you've entered a page title first
Empty title error:
- The extension requires a page title to generate the permalink
- Enter a title in the Title field before clicking Generate URL
Technical Details
Extension Structure
directus-extension-permalink-generator/
├── dist/
│ └── index.js # Built extension
├── src/
│ ├── index.ts # Extension definition
│ └── interface.vue # Vue component
├── package.json
└── README.mdHow It Works
- User clicks "Generate URL" button
- Extension fetches current page data (title, parent) and validation existing of configured fields.
- Recursively builds path by following parent relationships
- Converts each title to URL-safe slug
- Combines path segments with forward slashes
- Updates permalink field with generated URL
License
MIT