Auto-generate hierarchical permalinks for pages in Directus based on parent-child relationships
npm install directus-extension-permalink-generator$ npm i directus-extension-permalink-generator
$ npm i directus-extension-permalink-generator
node_modules/directus-extension-permalink-generator
extensions/directus-extension-permalink-generator and restart Directus docker.
npx directus-template-cli@latest apply)
parent
bash
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 build
`
The built extension will be in the dist/ folder.
$3
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
`bash
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 restart
`
$3
1. Go to Settings → Data Model → Pages
2. Click on the permalink field
3. Under Interface, select Permalink Generator
4. Input Title field, Parent, URL prefix, Placeholder page which are existing in the data model/schema
5. Save changes
Usage
When creating or editing a page:
1. Enter the page Title which you configured at the Permalink interface
2. Optionally select a Parent page which you configured at the Permalink interface. Note: a page cannot set parent is itself
3. Click the Generate URL button next to the permalink field
4. The permalink will be automatically generated based on the hierarchy
#### Note:
- Depending on value of the filed URL prefix, final URL will be appended from this field.
- If you don't want to use the url from the parent page. Click on the clear (x) button of the Parent page's combo-box to remove the current selection before re-generating new URL.
$3
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:
`bash
npm run dev
`
$3
Enable debug logging in browser console (F12):
1. Open browser DevTools
2. Go to Console tab
3. Click "Generate URL" button
4. 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.json has "host": "^11.0.0"
- Extension must be in extensions/ directory (not extensions/interfaces/)
Generate button not working:
- Check browser console (F12) for errors
- Ensure the parent field 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
$3
`
directus-extension-permalink-generator/
├── dist/
│ └── index.js # Built extension
├── src/
│ ├── index.ts # Extension definition
│ └── interface.vue # Vue component
├── package.json
└── README.md
``