diff --git a/auto_tag_plugin/auto_tag_plugin.php b/auto_tag_plugin/auto_tag_plugin.php index fc8ed20..b947852 100644 --- a/auto_tag_plugin/auto_tag_plugin.php +++ b/auto_tag_plugin/auto_tag_plugin.php @@ -188,7 +188,7 @@ function calculate_tags(array $keywordsToTags, array $searchContents): array return $tagScores; } -function filter_and_limit_tags(array $tagScores, int $minScore = 2, int $maxTags = 7): array +function filter_and_limit_tags(array $tagScores, int $minScore = 2, int $maxTags = 3): array { // Filter tags with a score greater than or equal to the minimum required $filteredTags = array_filter($tagScores, function ($score) use ($minScore) { @@ -207,11 +207,12 @@ function apply_auto_tags(array $data, ConfigManager $conf): array if (empty($data['link']['url'])) { return $data; } + $keywordsToTags = $conf->get('plugins.AUTO_TAG_KEYWORDS', []); $pageContent = fetch_page_content($data['link']['url']); $searchContents = [ - 'title' => $data['link']['title'], + 'title' => $data['link']['title'] ?? '', 'url' => $data['link']['url'], 'description' => $data['link']['description'] ?? '', 'existing' => implode(' ', explode(' ', $data['link']['tags'] ?? '')), @@ -224,11 +225,12 @@ function apply_auto_tags(array $data, ConfigManager $conf): array // Filter and limit tags $tagsToAdd = filter_and_limit_tags($tagScores); - $tagsToAdd[] = 'auto-tagged'; // Added a fixed tag - $existingTags = array_map('trim', explode(' ', $data['link']['tags'])); + $tagsToAdd[] = 'auto-tagged'; // Add a fixed tag to indicate auto-tagging + $existingTags = array_map('trim', explode(' ', $data['link']['tags'] ?? '')); $tagsToAdd = array_map('trim', $tagsToAdd); - $data['link']['tags'] = trim(implode(' ', array_filter(array_unique(array_merge($existingTags, $tagsToAdd))))); + // Merge, remove duplicates, and clean up + $data['link']['tags'] = trim(implode(' ', array_unique(array_merge($existingTags, $tagsToAdd)))); return $data; } @@ -236,7 +238,7 @@ function apply_auto_tags(array $data, ConfigManager $conf): array function hook_auto_tag_plugin_render_editlink(array $data, ConfigManager $conf): array { if (!$data['link_is_new']) { - //return $data; // Do not reapply for non-new links + // return $data; // Only auto-tag new links } return apply_auto_tags($data, $conf);