Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持自定义归档方式,目前可支持year和month #1502

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion install.php
Expand Up @@ -300,7 +300,8 @@ function install_get_default_options(): array
'attachmentTypes' => '@image@',
'secret' => \Typecho\Common::randString(32, true),
'installed' => 0,
'allowXmlRpc' => 2
'allowXmlRpc' => 2,
'postArchiveType' => 'month'
];
}

Expand Down
10 changes: 10 additions & 0 deletions var/Widget/Contents/Post/Date.php
Expand Up @@ -36,6 +36,16 @@ protected function initParameter(Config $parameter)
*/
public function execute()
{
var_dump(isset($this->options->postArchiveType));
sy-records marked this conversation as resolved.
Show resolved Hide resolved
if (isset($this->options->postArchiveType)) {
switch ($this->options->postArchiveType) {
case 'year':
$this->parameter->setDefault('format=Y&type=year', true);
break;
case 'month':
$this->parameter->setDefault('format=F Y&type=month', true);
sy-records marked this conversation as resolved.
Show resolved Hide resolved
}
}
/** 设置参数默认值 */
$this->parameter->setDefault('format=Y-m&type=month&limit=0');

Expand Down
1 change: 1 addition & 0 deletions var/Widget/Options.php
Expand Up @@ -97,6 +97,7 @@
* @property array $plugins
* @property string $secret
* @property bool $installed
* @property string $postArchiveType
*/
class Options extends Base
{
Expand Down
13 changes: 12 additions & 1 deletion var/Widget/Options/General.php
Expand Up @@ -91,7 +91,8 @@ public function updateGeneralSettings()
'allowRegister',
'allowXmlRpc',
'lang',
'timezone'
'timezone',
'postArchiveType'
);
$settings['attachmentTypes'] = $this->request->getArray('attachmentTypes');

Expand Down Expand Up @@ -291,6 +292,16 @@ public function form(): Form
);
$form->addInput($attachmentTypes->multiMode());


/** 归档类型 */
$postArchiveType = new Form\Element\Radio(
'postArchiveType',
['year' => _t('按年归档'), 'month' => _t('按月归档')],
$this->options->postArchiveType,
_t('归档类型')
);
$form->addInput($postArchiveType);

/** 提交按钮 */
$submit = new Form\Element\Submit('submit', null, _t('保存设置'));
$submit->input->setAttribute('class', 'btn primary');
Expand Down