Skip to content

Title2Slug is a PHP tool to generate SEO-friendly slugs for Persian product names. It reads names from a CSV file, calls an AI API (OpenAI or a third-party AI) in chunks, retries on invalid responses, and writes the results to a new CSV file. Additionally, it provides a script to check for duplicate slugs.

License

Notifications You must be signed in to change notification settings

BaseMax/title2slug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Title2Slug

Title2Slug is a PHP tool to generate SEO-friendly slugs for Persian product names. It reads names from a CSV file, calls an AI API (OpenAI or a third-party AI) in chunks, retries on invalid responses, and writes the results to a new CSV file. Additionally, it provides a script to check for duplicate slugs.


Features

  • Reads Persian product names from a CSV (input.csv).
  • Generates SEO-friendly slugs using AI in chunks of 10.
  • Supports OpenAI API or a third-party AI API (talkai.info).
  • Automatic retry on invalid JSON or empty responses.
  • Writes results to output.csv with an added نامک column.
  • Fully configurable via PROMPT.txt and script variables.
  • Checks for duplicate slugs using check_duplicates.php.
  • Easy to extend and integrate into other workflows.

Installation

  1. Clone the repository:
git clone https://github.com/BaseMax/title2slug.git
cd title2slug
  1. Place your input CSV file as input.csv. The CSV must contain a column نام with product names.

  2. Edit PROMPT.txt to customize the AI prompt. Use $INPUTS as a placeholder for the product names array.

  3. (Optional) Configure your OpenAI API key in title2slug.php:

$openaiApiKey = 'YOUR_OPENAI_API_KEY';
$openaiApi = true; // set to true to use OpenAI

Usage

1. Generate Slugs

Run the script from the command line:

php title2slug.php

The script will:

  1. Read input.csv.
  2. Generate slugs in chunks.
  3. Retry if any chunk returns invalid JSON.
  4. Write the output to output.csv with an additional نامک column.

Example output CSV:

شناسه نام نامک
3433 سیستم صوتی SSE2.v2 - فکتور sse2v2-audio-system-factor
3434 پریز برق روکار UPO2 - فکتور upo2-surface-mounted-power-outlet-factor
3435 شارژر وایرلس BWC1.v2 - فکتور bwc1v2-wireless-charger-factor

2. Check for Duplicate Slugs

After generating slugs, you can check for duplicates with:

php check_duplicates.php

The script will list all duplicate نامک entries along with their corresponding شناسه values, helping you quickly identify conflicts.


Configuration

  • $inputCsv: Path to input CSV.
  • $outputCsv: Path to output CSV.
  • $promptFile: Path to AI prompt text file.
  • $maxChunkSize: Number of items processed per AI request (default: 10).
  • $openaiApi: Boolean to switch between OpenAI API and third-party AI.
  • $openaiApiKey: Your OpenAI API key.

Notes

  • The script handles JSON wrapped in triple backticks (```) from the third-party API.
  • Slug count mismatches are automatically padded with empty strings.
  • Ensure your CSV uses UTF-8 encoding to prevent Persian character issues.
  • check_duplicates.php requires output.csv generated by title2slug.php.

License

This project is licensed under the MIT License.


Copyright

© 2025 Max Base

About

Title2Slug is a PHP tool to generate SEO-friendly slugs for Persian product names. It reads names from a CSV file, calls an AI API (OpenAI or a third-party AI) in chunks, retries on invalid responses, and writes the results to a new CSV file. Additionally, it provides a script to check for duplicate slugs.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages